对于迭代/映射反应的孩子,哪种方法更好/更安全,一般建议?
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)
React.Children.map更好,因为它处理null和undefined案件.
如果children为null或undefined,则返回null或undefined而不是数组.
| 归档时间: |
|
| 查看次数: |
865 次 |
| 最近记录: |