In React v16.2.0, there is a new API call React.Children
.
I am curious whats the different between React.Children
and use children
directly.
For example, if I want to manipulate the children content, I can do the trick in both methods. example
const Child = () => (
<div>child</div>
)
class App extends React.Component {
render() {
const template1 = React.Children.map(this.props.children, (child) => {
return React.cloneElement(child);
});
const template2 = this.props.children.map((child) => {
return React.cloneElement(child);
});
return [template1, template2];
}
}
And the result is the same.
Does anyone know what is the different?
Or what is the purpose for react team to release this API.
Thank you.