简体   繁体   中英

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()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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