This is in a functional component.
I have a submit()
function that looks like so:
async function handleSubmit(event) {
event.preventDefault();
try {
let resp = await fetch("FOOBAR/BAX", {
method: 'POST',
body: JSON.stringify({ /*stuff*/})
});
if (resp.ok){
// yadda yadda yadda
props.history.push("/"); // navigate
}
}
}
Now, when I cause navigation to occur I'm getting the dreaded 'Can't perform a React state update on an unmounted component.' error.
So, using effects, how do I make sure this fetch call is cleaned up? All the examples I'm seeing use useEffect
to both set up and then cleanup the call (with cleanup function).