Last active
June 11, 2019 04:11
-
-
Save joshuaaguilar20/ece1dafa0ca5e0bf9f1934d4317daadd to your computer and use it in GitHub Desktop.
Reducers
This file contains hidden or 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
`Notes Reducer uses previous state anf object. | |
Takes in Action/ Undefined | |
Gets Previous State and Action | |
First Agrument into Reducer is always going to be returned the last time it was ran | |
only change is ACTION OBJECT | |
Reducers are PURE- huh? | |
anytime we call reducer we are not suppose to do anything else like dom, API etc. | |
when reducer gets call it just get action and value | |
do computation with state and action | |
(* DO NOT MUTATE STATE EVER* ) | |
See Above . use spread op, etc instead of mutating state directly.` | |
export defualt (state = [], action ) => { | |
switch(action.type){ | |
case 'FETCH_POST': | |
return action.payload | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment