Skip to content

Instantly share code, notes, and snippets.

@sag1v
Last active October 25, 2019 20:41
Show Gist options
  • Save sag1v/58a17b63e3510fa382220d31ff916659 to your computer and use it in GitHub Desktop.
Save sag1v/58a17b63e3510fa382220d31ff916659 to your computer and use it in GitHub Desktop.
Markdium-React state update on an unmounted component
const initialState = { loading: false, selectedPet: "", petData: null }
function petsReducer(state, action) {
switch (action.type) {
case "PET_SELECTED": {
return {
...state,
selectedPet: action.payload
};
}
case "FETCH_PET": {
return {
...state,
loading: true,
petData: null
};
}
case "FETCH_PET_SUCCESS": {
return {
...state,
loading: false,
petData: action.payload
};
}
case "RESET": {
return initialState;
}
default:
throw new Error( `Not supported action ${action.type}` );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment