-
Book Overview & Buying
-
Table Of Contents
React Application Architecture for Production..
By :
Local state is the simplest and most fundamental type of state in React. It lives within a single component and is only accessible to that component and its children if passed down as props. This encapsulation makes local state easy to reason about and maintain.
We should try to keep the state as close to the component that needs it as possible. If a piece of state is only needed within a small portion of the application and does not need to be persisted, there's no reason to make it more complicated. This principle of keeping state colocated helps us avoid unnecessary complexity and makes our components more reusable.
Let's look at a practical example from our application. When we try to create a new review from the idea detail page, we need to track whether the review modal is open or closed.
First, we need to click the "Write Review" button:

Figure 6.1 – Write Review button
When we click the button, the review modal should open:

Figure...