Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 597
Oscar Fanelli Avatar asked Jun 07 '26 04:06

Oscar Fanelli


1 Answers

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

like image 188
Mahesh Haldar Avatar answered Jun 08 '26 17:06

Mahesh Haldar