You can also create nested components using React.createElement , but for this you need to execute special syntax.
tag should be type and attribs should be props , but you can props over your object and rename these keys, if necessary, so that there is no problem.
Now something like this:
var data = { "type": "div", "props": {anyProp: true}, "children": [ { "type": "p", "props": {}, "children": [], "text": "test" }, { "type": "div", "props": {}, "children": [ { "type": "p", "props": {}, "children": [], "text": "hi" } ] } ] }
You can simply use React.createElement(data.type, data.props, data.children); to create a component, including all children, properties, and so on.
source share