反应儿童迭代

Raf*_*iak 3 reactjs

对于迭代/映射反应的孩子,哪种方法更好/更安全,一般建议?

this.props.children.map(c => <span>new child</span>);
Run Code Online (Sandbox Code Playgroud)

要么

React.Children.map(c => <span>new child</span>);
Run Code Online (Sandbox Code Playgroud)

pwo*_*laq 7

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

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