简体   繁体   English

为什么map()在这种情况下得到2个参数?

[英]Why does map() get 2 arguments in this case?

Could you help me, please, I can't understand why there are 2 arguments in the map() 请帮帮我,我不明白为什么地图中有2个参数()

Children.map(this.props.children, child =>              
        <button>{child} </button>   

I supposed that this construction should work 我认为这种结构应该有效

Children.map(child =>           
        <button>{child} </button>

But it doesn't. 但事实并非如此。

React.Children map API takes the first argument as the children array to iterate on and the second argument as the callback function that is called with each of the iterated children React.Children map API将第一个参数作为要迭代的子数组,将第二个参数作为每个迭代子项调用的回调函数

Unlike the normal map which is the prototype of the Array constructor function, in the above case map is a function defined for the Children Object and needs to be passed with the array it has to iterate on 与作为Array构造函数原型的法线贴图不同,在上面的案例中, map是为Children对象定义的函数,需要与必须迭代的数组一起传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM