Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listener for state changes in reactjs

I have a component with a couple of input fields that updates the state of the component using the valueLink={this.linkState('foo')} facility provided by React.addons.LinkedStateMixin.

Prior to this I was using the onChange handler to communicate the changes back to the server using a websocket connection, so I was wondering if I could replicate this behaviour somewhat and post the changes in the state back using a "state change listener" of some sorts?

like image 223
Hamza Avatar asked Oct 31 '14 20:10

Hamza


People also ask

What happens when state is changed React?

React components has a built-in state object. The state object is where you store property values that belongs to the component. When the state object changes, the component re-renders.

Can I use addEventListener in React?

When using React, you generally don't need to call addEventListener to add listeners to a DOM element after it is created. Instead, just provide a listener when the element is initially rendered. You have to be careful about the meaning of this in JSX callbacks. In JavaScript, class methods are not bound by default.

Which method is used to change the state data in React?

setState" function is used to change the state of the React. js component.

Can we directly modify state in React?

React will then look at the virtual DOM, it also has a copy of the old virtual DOM, that is why we shouldn't update the state directly, so we can have two different object references in memory, we have the old virtual DOM as well as the new virtual DOM.


1 Answers

Looks like the method I am looking for is componentDidUpdate()

like image 83
Hamza Avatar answered Oct 07 '22 02:10

Hamza