Skip to content

Instantly share code, notes, and snippets.

@sag1v
Last active October 25, 2019 20:43
Show Gist options
  • Save sag1v/8abf84e41d18896362e9a9a6427d3bc1 to your computer and use it in GitHub Desktop.
Save sag1v/8abf84e41d18896362e9a9a6427d3bc1 to your computer and use it in GitHub Desktop.
Markdium-React state update on an unmounted component
function App() {
const [showPets, setShowPets] = useState(true);
const toggle = () => {
setShowPets(state => !state);
};
return (
<div>
<button onClick={toggle}>{showPets ? "hide" : "show"}</button>
{showPets && <Pets />}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment