I have a simple node.js app that should be responding to requests with pure HTML using React's renderToString
function. The code for rendering and responding looks like this:
const markup = renderToString(
<Provider {...stores}>
<Router location={req.url} context={{}} history={browserHistory}>
<Routes/>
</Router>
</Provider>
);
res.status(200).send(markup);
And the HTML response:
<section data-reactroot="">
<h1>Header</h1>
<div>Body</div>
</section>
I don't want any trace of react in the output. Is there a way, when rendering with react, to not include the data-reactroot
or any other traces of react?
Just use renderToStaticMarkup
instead of renderToString
and there wont be any trace of react in the output (reference https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup)