-
Book Overview & Buying
-
Table Of Contents
React Application Architecture for Production - Second Edition
By :
In this chapter, we explored the five main types of state in React applications and learned when and how to use each approach.
We started with local state, the simplest form of state management using React's useState hook. Local state is perfect for UI state that's self-contained within a single component, such as whether a modal is open or closed. We learned to always start with local state and only move to more complex solutions when necessary.
Next, we examined global state management with Zustand. Global state is useful for data that needs to be accessed from multiple components throughout the application, such as notifications or authentication status. We implemented a notifications system that can be triggered from any component, demonstrating how global state enables features that transcend component boundaries.
We then looked at asynchronous state management with React Query. Server state has unique challenges including loading states, errors, caching...