Return DOM element in render function of React component
Here's a simple example.
render() {
const newNode = document.createElement('p');
return <div ref={(nodeElement) => {nodeElement && nodeElement.appendChild(newNode)}}/>
}
Render a normal JSX div
. Use ref
inside.
Inside the ref
callback use .appendChild(node)
See https://reactjs.org/docs/refs-and-the-dom.html