Chapter 2: Using Local and Global States

React components form a tree structure. In the tree structure, creating a state in a whole subtree is straightforward; you would simply create a local state in a higher component in a tree and use the state in the component and its child components. This is good in terms of locality and reusability and is why it's generally recommended to follow this strategy.

However, in some scenarios, we have a state in two or more components that are far apart in the tree. In such cases, this is where global states come in. Unlike local states, global states do not conceptually belong to a specific component, and so where we store a global state is an important point to consider.

In this chapter, we will learn about ...

Get Micro State Management with React Hooks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.