Design Patterns · Junior · Question 19 of 75
What does the State pattern describe?
- ✓Correct answer: An object changes its behavior based on its state, like a finite state machine
- 2Storing all of the app's data in one global store
- 3Saving a component's state to
localStoragebetween sessions
Explanation
Instead of scattered if (status === ...) checks, each state's behavior is described separately, and transitions are explicit: idle → loading → success | error. On the frontend this idea is often implemented with state machines (XState) or useReducer with a discriminated union.