How to pass props to {this.props.children}

后端 未结 26 3832
猫巷女王i
猫巷女王i 2020-11-21 23:42

I\'m trying to find the proper way to define some components which could be used in a generic way:


  
  

        
26条回答
  •  醉梦人生
    2020-11-22 00:27

    Further to @and_rest answer, this is how I clone the children and add a class.

    {React.Children.map(this.props.children, child => React.cloneElement(child, {className:'child'}))}

提交回复
热议问题