When to manage state locally?

Hi. In the React and Redux section you end up writing a component that manages some state locally and some with redux. I’m not clear on when when you should choose local state management vs redux management.

Choosing a State management technique depeneds on the complexity project. You can use the solution which fits your project needs and works for you.

1 Like

Use redux state when state is used by two or more components that are not in a child parent relationship or if they are, is up to you to decided when to stop passing state via props.

Otherwise use component based state.

You may ask why this?

Well, the need for tools like redux emerged from a few problems.

One is props drilling through parent-child components.
When you have to give state to D from A. For example A -> B -> C -> D.
In this case the state is passed through B and C as props, although B and C have no need for it.

Another one was the need of sharing state between components that do not relate as parent-child.

For example A -> B and E -> D, (A and E are siblings) with redux you can share state to B to E to D or A.

A third one would be the need of having a single source of truth for state.

1 Like

It actually depends on how complex your state is. You don’t need Redux for a simple state. A component state will suffice. While knowing Redux helps you understand state management at a deeper level (at least from my experience ), there is a simpler alternative to redux. The context API + hooks will handle most of your state management which to the best of my knowledge the tutorial doesn’t cover.

1 Like