in React JS by
Q:

What is React.cloneElement? And the difference withthis.props.children?

1 Answer

0 votes
by

React.cloneElement clone and return a new React element using using the passed element as the starting point. The resulting element will have the original element's props with the new props merged in shallowly. New children will replace existing children. key and ref from the original element will be preserved.

React.cloneElement only works if our child is a single React element. For almost everything {this.props.children} is the better solution. Cloning is useful in some more advanced scenarios, where a parent send in an element and the child component needs to change some props on that element or add things like ref for accessing the actual DOM element

Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Jun 19, 2020 in React JS by JackTerrance
0 votes
asked Nov 26, 2019 in React JS by AdilsonLima
0 votes
asked Oct 9, 2019 in React JS by Indian
0 votes
asked May 20, 2020 in React JS by GeorgeBell
0 votes
asked May 20, 2020 in React JS by GeorgeBell
...