【发布时间】:2018-10-01 22:40:12
【问题描述】:
我有一个包含无状态功能组件的 React 组件。内部组件在值数组上运行 Lodash map 以返回 p 标签数组。
class Application extends React.Component {
items = [
'first',
'second',
'third',
];
render() {
return <div>
<Paragraphs items={ this.items } />
</div>;
}
}
const renderItem = ( item, index ) => {
return (
<p key={ index }>{ item }</p>
);
};
const Paragraphs = ( { items } ) => _.map( items, renderItem );
ReactDOM.render(<Application />, document.getElementById('root'));
我的Application 组件需要对这些DOM 元素的引用,所以我想将每个p 标记的引用传回给父组件。谁能建议最好的方法来做到这一点?我发现的所有示例都假设子组件是单个元素。
【问题讨论】:
-
你读过文档吗? reactjs.org/docs/…
-
我做到了,谢谢。我的问题更多与处理元素数组有关。
标签: javascript html reactjs dom reference