DEV Community

shah-ms
shah-ms

Posted on

State Management in React

In the examples given on React's website, I have a doubt in the Counter App example. I'm confused with how do I assign states in the app. Does each item is assigned a state & how to update the state using setState() ?
What should be the thinking process?
Please help. Thank you!

#reactjs #states #counterApp

Top comments (2)

Collapse
 
mememe profile image
mememe

hi @shah-ms.

A state can contain a lot of data depending on your app. You can retrieve data from an API and you can store data for your app.

Using state hooks and using this.state and this.setState are common ways to handle state management in React.

Collapse
 
ivomeissner profile image
Ivo Meißner

Have you looked at React hooks? reactjs.org/docs/hooks-state.html

I feel like that makes state handling way easier. In new codebases I even have the rule to only add functional components and use hooks, instead of class-based components.