ReactDOMServer.renderToStaticMarkup
Earlier in this chapter, we used React on the server side to generate HTML. The HTML generated by React on the server and client side contains data-reactid
attributes, which are used by React internally. On the client side, it makes sense to have data-reactid
, as it is used during reconciliation and other processes and features.
You must be wondering what the point of adding this attribute on the server side is. Actually, it is added so that if you call ReactDOM.render()
on the client side on a node that already has React server-rendered markup, React will preserve it and only reconcile it.
If you don't want data-reactid
attributes to be generated on the server side, you can use renderToStaticMarkup
instead of renderToString
.