Ben Bud Ben Bud - 20 days ago 12
React JSX Question

Manually create a react element Object with streaming

Is it possible to create a react element object manually without using react.createElement.

The idea is to create nested react elements tree while streaming from html. The problem is I am unaware of nested children during streaming.

My objective is to be able to create a react element from a nested object. ie:

{
   "tag": "div",
   "attribs": {},
   "children": [
      {
         "tag": "p",
         "attribs": {},
         "children": [],
         "text": "test"
      },
      {
         "tag": "div",
         "attribs": {},
         "children": [
            {
               "tag": "p",
               "attribs": {},
               "children": [],
               "text": "hi"
            }
         ]
      }
   ]
}

Answer Source

This is now possible with the release of React 16 which now introduces renderToNodeStream and renderToStaticNodeStream.

Sasha Aickin touches on how it works in this article: https://medium.com/@aickin/whats-new-with-server-side-rendering-in-react-16-9b0d78585d67