January 2020
Intermediate to advanced
470 pages
11h 13m
English
We can see another example that involves assigning functions. As we mentioned earlier in this chapter, React-Redux works by dispatching actions that are processed by a reducer. Usually, the reducer includes code with a switch:
function doAction(state = initialState, action) { let newState = {}; switch (action.type) { case "CREATE": // update state, generating newState, // depending on the action data // to create a new item return newState; case "DELETE": // update state, generating newState, // after deleting an item return newState; case "UPDATE": // update an item, // and generate an updated state return newState; default: return state; }}
Read now
Unlock full access