Advanced State with Reducers
Readings
useReducer hook
-
Name an alternative to the useState Hook.
-
Why might the useReducer Hook be preferable to the useState Hook?
- helps you manage complex state logic in React applications
-
What are two ways to set the initial state?
- pass the initial state as a second argument/pass an init function as a third argument
Ultimate Guide to useReducer
-
In terms of state, what does useReducer expect to receive as a parameter?
- reducer function as the first and the initial state as the second
-
What does useReducer return?
- returns an array that holds the current state value and a
dispatch function to which you can pass an action and later invoke it
-
Explain dispatch to a non-technical recruiter.
- basically it sends the type of action to the reducer function, which updates state
Reflection
- What are your learning goals after reading and reviewing the class README?
- I’m looking forward to the lecture tomorrow on how the reducer function works in the code we’re working on