React.js: Is it possible to convert a react component to HTML DOM's?

后端 未结 5 555
孤城傲影
孤城傲影 2021-02-05 05:14

I\'m working on a map-based app that uses Google Map API to create markers and its info window in React.js. The infowindow.setContent() only accepts either a

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 05:56

    You can render a ReactElement in a detached DOM Node via React.render. Thus, the following code should work for you.

    createMarker: function() {
    
      /** Some other lines of code */
    
      _this = this;
    
      google.maps.event.addListener(marker, 'click', function() {
    
        var div = document.createElement('div');
        ReactDOM.render( _this._renderInfoWindow(place), div );
        infowindow.setContent( div );
        infowindow.open(map, this);
    
      });
    
    },
    

提交回复
热议问题