mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
617 B
617 B
useUnmountPromise
A life-cycle hook that provides a higher order promise that does not resolve if component un-mounts.
Usage
import useUnmountPromise from 'react-use/lib/useUnmountPromise';
const Demo = () => {
const mounted = useUnmountPromise();
useEffect(async () => {
await mounted(someFunction()); // Will not resolve if component un-mounts.
});
};
Reference
const mounted = useUnmountPromise();
mounted(promise);
mounted(promise, onError);
onError— if promise rejects after the component is unmounted,onErrorcallback is called with the error.