P
P
Pipop2021-01-15 17:41:39
React
Pipop, 2021-01-15 17:41:39

How to add children using React.cloneElement?

For example, there is a code

React.cloneElement(children, { ...children.props, id }, children.props.children)


In addition to the children of the child (sorry for the pun), how can I also add, say, another div?
Upon attempt
React.cloneElement(children, { ...children.props, id }, children: <div>Some test div</div>)

expectedly frays the original children

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question