gpt4 book ai didi

reactjs - React 子进程迭代

转载 作者:行者123 更新时间:2023-12-03 14:00:02 26 4
gpt4 key购买 nike

对于迭代/映射 React 的子项,哪种方法更好/更安全,一般推荐?

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

或者

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

最佳答案

React.Children.map 更好,因为它可以处理 nullundefined 情况。

If children is null or undefined, returns null or undefined rather than an array.

关于reactjs - React 子进程迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48182986/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com