State
Intermediate·20 min read·Lesson 3 of 4·○Not Started
State is data that changes over time. In React, state drives the UI — when state updates, the component re-renders to reflect the new data.
useState Hook
useState is the most basic hook for managing state in functional components. It returns a state variable and a setter function.
useReducer Hook
For complex state logic involving multiple sub-values or when the next state depends on the previous one, useReducer is a better choice.
State Management Patterns
- Lifting state up to the nearest common ancestor
- Colocating state as close as possible to where it's used
- Using context for global state that doesn't change frequently
- Using external libraries (Zustand, Redux) for complex global state