State Management
In this chapter, we’ll learn about shared state, which is state that is used by several different components. We will explore three approaches to managing shared state, discussing the pros and cons of each approach.
To do this, we will build a simple app containing a header that displays the user’s name, with the main content also referencing the user’s name. The user’s name will be stored in state that needs to be accessed by several components.
We will start with the simplest state solution. This is to use one of React’s state hooks to store the state and pass it to other components using props. This approach is often referred to as prop drilling.
The second approach we will learn about is a feature in React called context. We will learn how to create a context containing a state and let other components access it.
The last approach we will cover is a popular library called Redux. We will take the time to understand...