React.js: binding to existing elements

In Backbone.js, you can specify a view element using the el property or by calling view.setElement() .

Is there an equivalent way to connect a React.js component to an existing DOM element?

+6
source share
1 answer

I'm not very familiar with Backbone, but to connect the React component to the DOM, you use the renderComponent function. The first arg is the component, and the second is the DOM element:

 React.renderComponent(<SampleComponent />, document.getElementById('app')); 

Updated in the context indicated in the comments:

It hooks hooks to an element, replacing its contents, but not the element itself. You can call renderComponent() more than once on this element, and each time it will run the same algorithm. This is convenient if you want to transfer various details, preliminary visualization on the server or completely display another component. The same process is used to update the actual DOM every time, as if you were using setState() inside the component itself.

+10
source

All Articles