为什么this.props.children.map不起作用? [英] Why doesn't this.props.children.map work?
本文介绍了为什么this.props.children.map不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在其他几个组件中编写了这段代码,但似乎无法理解为什么这不起作用。
I have written this code in several other components but can't seem to understand why this isn't working.
{
this.props.children.map(function(child) {
return <li>{child}</li>
})
}
任何帮助都将不胜感激!
Any help would be greatly appreciated!
推荐答案
this.props.children
是一个不透明的数据结构。它可以是数组或单个元素。在您的情况下, this.props.children
可能是单个元素,这就是 .map()
方法的原因未定义。
this.props.children
is an opaque data structure. It can be either an array or a single element. In your case, this.props.children
is probably a single element, which is why the .map()
method is undefined.
您应该使用 React.Children
API 操纵子项
prop。
You should use the React.Children
API when manipulating the children
prop.
另请参阅儿童道具类型。
这篇关于为什么this.props.children.map不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文