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