I am trying to optimize my react code by fixing any memory leaks. For this i am using createAsyncThunk canceling-while-running.
I am successful in implementing this using useEffect where I dispatch a reducer to request, when the component mounts and i could automatically trigger abort() signal when the component unmounts using the return of useEffect. Refer the below code:
useEffect(() => {
const promise = dispatch(getIssuedBooks())
return promise.abort()
}, []);
But i have other reducers which get dispatched on onClick events. Refer the code below:
const handleRequest = (id) => {
dispatch(requestBook(id))
}
My problem is when component unmounts how do i abort from this request. I tried some things but it did not work out. Please help. Thanks in advance.