011. The Dispatch Paradigm
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
In useState, you update values directly. In useReducer, you 'dispatch' actions. This level of indirection is a massive benefit for complex logic. Instead of your component knowing the math for how to increment a score or filter a list, it simply says 'SCORE_INCREMENTED' or 'FILTER_APPLIED'. The reducer function, which lives outside the component's render cycle, handles the implementation details.
022. The Immutable State Machine
Reducers are essentially state machines. They take a state and an event (action) and transition to the next state. Because reducers must be pure functions, they provide perfect predictability. They never mutate state; they always return a fresh copy. This makes them incredibly easy to test—you can verify your business logic without even mounting a React component.
?Frequently Asked Questions
What is the useState hook?
useState is a React Hook that lets you add state variables to functional components. It returns the current state value and a function to update it.
When should I use useEffect?
The useEffect hook is used to perform side effects in components, such as fetching data from an API, subscribing to events, or manually updating the DOM.
What are React Hooks?
React Hooks are functions that let you 'hook into' React state and lifecycle features from function components without needing to write a class component.
