Is it ok to use ReactDOMServer.renderToString in the browser in areas where React isn't directly managing the DOM?
According to the new documentation: https://reactjs.org/docs/react-dom-server.html
The following methods can be used in both the server and browser environments:
- renderToString()
- renderToStaticMarkup()
I know it is too old question, but since it has not been answered I wanted to share my thoughts.
I was using the same thing, renderToString
, but as the documentation recommends not to use it on client-side, I achieved it in another way, by using the react-dom
's render
method to render the custom component into div
var myDiv = document.createElement('div');
ReactDOM.render(
<MarkerContents data={this.props.data} />,
myDiv
);
var myIcon = L.divIcon({
iconSize: new L.Point(50, 50),
html: myDiv.innerHTML
});