useReducer
useReducer is a React Hook that lets you add a reducer to your component.
const [state, dispatch] = useReducer(reducer, initialArg, init?)- Reference
- Usage
- Troubleshooting
- I’ve dispatched an action, but logging gives me the old state value
- I’ve dispatched an action, but the screen doesn’t update
- A part of my reducer state becomes undefined after dispatching
- My entire reducer state becomes undefined after dispatching
- I’m getting an error: “Too many re-renders”
- My reducer or initializer function runs twice