Skip to content

Instantly share code, notes, and snippets.

@joshuaaguilar20
Last active June 11, 2019 04:11
Show Gist options
  • Save joshuaaguilar20/ece1dafa0ca5e0bf9f1934d4317daadd to your computer and use it in GitHub Desktop.
Save joshuaaguilar20/ece1dafa0ca5e0bf9f1934d4317daadd to your computer and use it in GitHub Desktop.
Reducers
`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