Why Do State Management?

What is a state?

Throughout the course, we’ve been using the useState hook. We know that in React Native, state is a piece of data that we need to track that indicates the condition of a particular component within the app. If we recall our real world example earlier in the course, we talked about how a light switch has two states—on and off.

In React Native, a piece of information can change as a result of changing the UI. For example, this piece of information could be whether the user is logged in or not or a list of the posts the current user has created.

What is state management?

Previously, we stored the state of each component in the component itself. This method works well for small applications. However, in large applications, the states of components frequently overlap. There may be some states that are shared by multiple components.

When components share states, it becomes challenging to handle them in large applications. A state management design pattern can be used to solve this problem.

A state management design pattern can be thought of as creating a single location to store all of the states, from which the various components can access the data.

Why do we need state management?

Let’s look at a hypothetical application. It has the following component structure.

Get hands-on with 1400+ tech skills courses.