Created
October 25, 2019 20:23
-
-
Save sag1v/dbec3f661d19d8d0586c57dd2a8a5b65 to your computer and use it in GitHub Desktop.
Markdium-React race condition bug
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