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).
handleSubmitfunction. I don't see anything to clean here. Would you care to share more code, maybe on stackblitz?handleSubmitfunction doesn't appear to update state (unless it is hidden within the yadda yadda yadda bit). About usinguseEffecthook to cancel a fetch request you can use an abort controller with the fetch request. Let us know if you need help with that. In the mean time , as yonki requested, can you share more of the component code or share a link to it in stackblitz or codesandbox?