[英]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. 我正在向客户端发送一个加载器,并且在渲染加载器之后,我想从服务器接收我的主要React.js组件。
I'm using node.js with express on the backend and i'm using the "express-react-views" engine for rendering. 我正在后端使用带有express的node.js,并且正在使用“ express-react-views”引擎进行渲染。
So, how can I safely transfer components from the server to the client? 那么,如何安全地将组件从服务器传输到客户端?
Thanks a lot. 非常感谢。
var htmlOfComponent = ReactDOMServer.renderToString(component);
send this htmlOfComponent as part of your initial html page request from server. 发送此htmlOfComponent作为服务器最初的html页面请求的一部分。
include react.js in script tags and send. 在脚本标签中包含react.js并发送。
For component data=> you can send that stringified in script tags too. 对于组件数据=>,您也可以将其字符串化发送到脚本标签中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.