Gaurav Singh
Gaurav Singh

Reputation: 85

Difference between react state and Javascript object

What is the difference between React State and Javascript objects? when the state changes the dom changes automatically and when objects change the dom is also changed.

Upvotes: 0

Views: 368

Answers (2)

Gaurav Roy
Gaurav Roy

Reputation: 12195

In React , The state object is where you store property values that belongs to the component. React is a javascript library so it uses javascript object as its state. In short React state is a javascript object .

When there is any change in the state via the setState func , then the DOM re-renders only to the specific part that has changed. Beauty of react , the virtual Dom.

Upvotes: 0

Nicolas Hevia
Nicolas Hevia

Reputation: 15837

React State IS a JavaScript object. The purpose is to keep track of changing information between renders.

The best part is that if you change the state inside a component, the virtual DOM will know which parts of the DOM need to be modified (instead of modify the whole DOM).

Upvotes: 1

Related Questions