3

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

2
  • Unless I'm misunderstanding, in react your ajax call shouldn't be responsible for changing the DOM. Rather, your ajax call should change the state of your react component, which causes a rerender and in turn should modify the dom. Generally, react should be the only thing responsible for modifying the dom. Commented May 14, 2016 at 16:04
  • I'm not in a single page application done by React. Only some components area "reacted", others are managed by jQuery for multiple reasons. Commented May 15, 2016 at 9:59

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

This is the good way if everything in your page is managed via React. In my website (for multiple reasons, it's not casual) something is "reacted", something not. Do you have a solution for my problem? Attach a listner and react when the class occur?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.