adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.55k stars 1.09k forks source link

Expose abort controller in useAsyncList #2217

Open CezCz opened 3 years ago

CezCz commented 3 years ago

🙋 Feature Request

I'd like to be able to abort fetch in useEffect cleanup when my component is detaching.

🤔 Expected Behavior

useAsyncList should expose a method to abort all it's current ongoing fetches.

😯 Current Behavior

Abort is not possible. This causes a following message being thrown to console: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

dannify commented 3 years ago

I think we should definitely clean up on unmount and we can investigate ways to allow fetches to be aborted directly.