Last active
October 25, 2019 20:41
-
-
Save sag1v/58a17b63e3510fa382220d31ff916659 to your computer and use it in GitHub Desktop.
Markdium-React state update on an unmounted component
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
| 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