my purpose is to render a div that i have already created by createElement .
And I have a did that into a ReactJs function so i need to return the div but doing it like that doesn't work
import React, { Component } from 'react';
class main extends Component {
renderList() {
var div = document.createElement("div");
var ul = document.createElement("ul");
div.appendChild(ul);
return div
}
render() {
return (
<div>
{this.renderList()}
</div>
);
}
}
export default main;
It gave me this error but when i did console.log(div) I do get
<div>......</div>
react-dom.development.js:2317 Uncaught Error: Objects are not valid as a React child (found: [object HTMLDivElement]). If you meant to render a collection of children, use an array instead.
How can I achieve that ? thnx
createElement(). If you have one (there are a FEW cases) then you should use a portal to render React code inside it. My gut feeling is: drop HTML DOM manipulation and write React code.renderList()? If it is like{ renderList() }then most probably you need to return from that function a valid JSX.document.createElementinstead of just using React components?render.