Is it ok to use ReactDOMServer.renderToString in the browser in areas where React isn't directly managing the DOM?

浪尽此生 提交于 2019-11-30 07:56:39

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
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!