3 Managing component state with the useReducer hook
This chapter covers
- Asking React to manage multiple, related state values by calling
useReducer
- Putting component state management logic in a single location
- Updating state and triggering re-renders by dispatching actions to a reducer
- Initializing state with initialization arguments and initialization functions
As your applications grow, it’s natural for some components to handle more state, especially if they supply different parts of that state to multiple children. When you find you always need to update multiple state values together or your state update logic is so spread out that it’s hard to follow, it might be time to define a function to manage state updates for you: a reducer
Get React Hooks in Action 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.