对于反应/映射反应儿童,一般建议使用哪种方法更好/更安全?
this.props.children.map(c => <span>new child</span>);
OR
React.Children.map(c => <span>new child</span>);
答案 0 :(得分:7)
React.Children.map
更好,因为它会处理null
和undefined
个案件。
如果children为null或undefined,则返回null或undefined而不是数组。