Why it’s not working like that?
let elem = <div></div>
elem.appendChild(<h1>abc</h1>)
how I can add child to jsx element?
Why it’s not working like that?
let elem = <div></div>
elem.appendChild(<h1>abc</h1>)
how I can add child to jsx element?
2
Answers
You don’t have
appendChild
in JSX. You would directly add the element in:Or, you can use different components:
React uses a virtual dom node, but appendChild can only work with real dom node.
You can solve this in 2 ways.