How to pass props to {this.props.children}
@lebyy▲ 0 net votes
Problem: I'm trying to find the proper way to define some components which could be used in a generic way: <Parent> <Child value="1"> <Child value="2"> </Parent> There is a logic going on for rendering between parent and children components of course, you can imagine… Fix (from the top answer): Cloning children with new props You can use React.Children to iterate over the children, and then clone each element with new props (shallow merged) using React.cloneElement . See the code comment why I don't recommend this approach. Using cloneElement is uncommon and can lead to fragile code. See common…