反应儿童迭代

时间:2018-01-10 08:16:50

标签: reactjs

对于反应/映射反应儿童,一般建议使用哪种方法更好/更安全?

this.props.children.map(c => <span>new child</span>);

OR

React.Children.map(c => <span>new child</span>);

1 个答案:

答案 0 :(得分:7)

React.Children.map更好,因为它会处理nullundefined个案件。

  

如果children为null或undefined,则返回null或undefined而不是数组。