Skip to content

Instantly share code, notes, and snippets.

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