Created
March 18, 2021 21:23
-
-
Save cassidoo/6479f5ea04aa4012619d3a91f478e0f6 to your computer and use it in GitHub Desktop.
Reducer content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1,2,3,4,5] | |
10 + 1 | |
11 + 2 | |
13 + 3 | |
16 + 4 | |
20 + 5 | |
let initialState = { | |
count: 0, | |
cake: 'fishy' | |
} | |
// dispatch | |
let actions = [ | |
{ type: "ADD", by: 40 }, | |
{ type: "MINUS", by: 10 }, | |
{ type: "BAKE_CAKE" } | |
] | |
let reducer = (state, action) => { | |
switch(action.type) { | |
case "ADD": { | |
return {...state, count: state.count + action.by} | |
} | |
case "MINUS": { | |
return {...state, count: state.count - action.by} | |
} | |
case "BAKE_CAKE": { | |
return { ...state, cake: "a lie" } | |
} | |
default: { | |
return state | |
} | |
} | |
} | |
let sum = actions.reduce(reducer, initialState) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment