How to use State in ReactJS || ReactJS Tutorials

Опубликовано: 15 Май 2026
на канале: Tech Talk
18
3

The state is user-defined, and it is a plain JavaScript object.

Components data will be stored in component's State.
It works like a local variable for the component.
This state can be modified based on user action. when a component state is changed, react observe the change and will re-render the component to the browser.


1. The only place where you can assign this.state is the constructor.
and Class components should always call the base constructor with props.

3. State Updates are Merged
4. State Updates May Be Asynchronous
React batch multiple setState() calls into a single update for performance.

Because this.props and this.state updated asynchronously, you should not rely on their values for calculating the next state.




There are three things you should know about setState().

setState works in an asynchronous way. That means after calling setState the this. state variable is not immediately changed.
setState() will always lead to a re-render unless shouldComponentUpdate() returns false.