When should you use useReducer instead of useState?
Model answer
useReducer is useful when state has several related values, or when the next state depends on complex rules. You dispatch actions such as { type: 'add', item }, and a pure reducer function returns the new state. This keeps all update logic in one place and makes it easier to test.
For a simple toggle or a text input, useState is enough.
Learn this topic
React useState Explained: Make Your Page React to Change in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.