Skip to content

Latest commit

Β 

History

History
30 lines (20 loc) Β· 617 Bytes

useUnmountPromise.md

File metadata and controls

30 lines (20 loc) Β· 617 Bytes

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, onError callback is called with the error.