Oscar Fanelli
Oscar Fanelli

Reputation: 3657

Render React component automatically after ajax call

With jQuery, I can attach an event handler function via the on method that will be triggered also when the DOM change and something (like an Ajax call) replace the HTML of the page.

Is it possible to do something similar with a React component? After an ajax call that changes the DOM, if an element with a specific class is found, render it (with ReactDOM.render(...)).

Thanks

Upvotes: 3

Views: 1623

Answers (1)

Mahesh Haldar
Mahesh Haldar

Reputation: 591

The component render responsibility should be given to react. Hence you should store the response from ajax call in the current state and react will handle the component rendering based on current state. Follow these APIs if you are using only react

https://facebook.github.io/react/docs/component-api.html

or follow connect() if you are writing in react-redux

Upvotes: 4

Related Questions