State Management · Middle · Question 5 of 75
What's the purpose of the third argument init in useReducer(reducer, arg, init)?
- ✓Correct answer: Lazy initialization:
init(arg)is called only on the first render - 2It's a middleware called before every action
- 3It defines the action types the reducer accepts
Explanation
useReducer(reducer, username, createInitialState) avoids recomputing an expensive initial state on every render - like a lazy initializer in useState. init can also be reused to reset the state.