7th Practical Class:
useReducer
Problem: Too Many useState
s
useReducer
:
"Advanced useState
"
Building Blocks:
- initial state: how state looks
- actions: "interactions"
- reducer: how to update state
Counter
Initial State
Actions
Reducer
useReducer
initialState
Actions
- simple object with all necesary data (like
id
, newtitle
, ...)
Action Creators
"function that returns action object"
action objects:
- action creators: