October 2019
Intermediate to advanced
426 pages
11h 49m
English
Now, we still need to define the function that handles these state changes. Such a function is known as a reducer function. It takes the current state and action as arguments, and returns a new state.
Now, we are going to define our reducer function:
function reducer (state, action) {
switch (action.type) {
case 'TOGGLE_EXPAND': return { ...state, expandPosts: !state.expandPosts }
Read now
Unlock full access