简体   繁体   中英

How could I send a React.js component from my node.js to my client?

I'm sending a client a loader, and I want to receive my main React.js components from the server, after rendering the loader.

I'm using node.js with express on the backend and i'm using the "express-react-views" engine for rendering.

So, how can I safely transfer components from the server to the client?

Thanks a lot.

    var htmlOfComponent = ReactDOMServer.renderToString(component);
  1. send this htmlOfComponent as part of your initial html page request from server.

  2. include react.js in script tags and send.

  3. For component data=> you can send that stringified in script tags too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM