Skip to content

Instantly share code, notes, and snippets.

@sag1v
Created October 25, 2019 20:23
Show Gist options
  • Save sag1v/b32d10936280ffe6fbca54123934b351 to your computer and use it in GitHub Desktop.
Save sag1v/b32d10936280ffe6fbca54123934b351 to your computer and use it in GitHub Desktop.
Markdium-React race condition bug
useEffect(() => {
let _previousKey = pets.selectedPet;
if (pets.selectedPet) {
dispatch({ type: "FETCH_PET" });
getPet(pets.selectedPet).then(data => {
if (_previousKey === pets.selectedPet) {
dispatch({ type: "FETCH_PET_SUCCESS", payload: data });
}
});
} else {
dispatch({ type: "RESET" });
}
}, [pets.selectedPet]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment