File size: 617 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# `useUnmountPromise`

A life-cycle hook that provides a higher order promise that does not resolve if component un-mounts.


## Usage 

```ts
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

```ts
const mounted = useUnmountPromise();

mounted(promise);
mounted(promise, onError);
```

- `onError` — if promise rejects after the component is unmounted, `onError`
  callback is called with the error.