DEV Community

Saran Chakravarthi
Saran Chakravarthi

Posted on Edited on

How to architecture state variables in React

Hello Devs, in this article, we will see how to architecture the state variables in your react app.

  • If a state is used by a single component it should be inside that component.

  • If a state is used by multiple components in a tree and they are all direct children of the same parent component, it should be in their parent component.

  • If a state is used by multiple components in a tree but they are not direct children of the same parent component, it should be in context/redux.

  • If a state is used by multiple components in different trees, it should be in context/redux.

I hope this article helped you. Want to connect with me? my DM is open on dev.to, you can connect with me on twitter

Happy coding!

Top comments (0)