reactjsexpressviewengine

Server side rendering of reactjs for express?


What is the best view engine/ method to pre-render a react component on an express backend? I'm at a loss at finding the most appropriate way to do it, all I can find in regards to resources are a bunch of article-tutorials, but they all do it in a different way, so I'm wondering if there is a recommended convention.

Essentially I just want to show 1 component with a bunch of pre-set props. No navigation or anything, just for 1 endpoint. I.e. You go to /component and it returns <Component prop1={1}/>


Solution

  • Just use the renderToString or renderToStaticMarkup methods if you just want the single component rendered and then send it in your response.

    See: ReactDOMServer