DEV Community

Discussion on: Avoiding race conditions and memory leaks in React useEffect

Collapse
 
havespacesuit profile image
Eric Sundquist

Additionally, you can check the status of the abort signal before doing any state-changing assignments.

if (!abortController.signal.aborted) { /* set state */}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
saranshk profile image
saransh kataria

Though that can be done, it will never return true since whenever the signal will be aborted, the code would enter the catch block because of the exception thrown.