I have a component where an abort controller is declared outside a useEffect. controller.abort() is called inside a useEffect when the component is unmounted.
When the component is unmounted this error below is thrown
Unhandled Rejection (AbortError): The operation was aborted.
const controller = new AbortController()
function MyComponent() {
useEffect(() => {
return () => controller.abort()
}, [])
const fetchData = async () => {
try {
const data = await fetchMyData(controller)
} catch(error) {
if (error.name === "AbortError") return
console.log("Error ", error)
}
}
}
What am I doing wrong?
stacktrace images

Check your index.js in root. If you are using StrictMode, that is exactly the problem. Checkout document: https://reactjs.org/docs/strict-mode.html. I think what you should do here is call request and abort in the same one.