Skip to content

Commit 28ef34b

Browse files
committed
docs: ✏️ add useUnmountedPromise reference
1 parent 797e54c commit 28ef34b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
- [`useMountedState`](./docs/useMountedState.md) — track if component is mounted.
112112
- [`usePromise`](./docs/usePromise.md) — resolves promise only while component is mounted.
113113
- [`useLogger`](./docs/useLogger.md) — logs in console as component goes through life-cycles.
114-
- [`useMount`](./docs/useMount.md) — calls `mount` callbacks.
114+
- [`useMount`](./docs/useMount.md) and [`useUnmountPromise`](./docs/useUnmountPromise.md) — tracks if component is mounted.
115115
- [`useUnmount`](./docs/useUnmount.md) — calls `unmount` callbacks.
116116
- [`useUpdateEffect`](./docs/useUpdateEffect.md) — run an `effect` only on updates.
117117
- [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that does not show warning when server-side rendering.

docs/useUnmountPromise.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# `useUnmountPromise`
2+
3+
A life-cycle hook that provides a higher order promise that does not resolve if component un-mounts.
4+
5+
6+
## Usage
7+
8+
```ts
9+
import useUnmountPromise from 'react-use/lib/useUnmountPromise';
10+
11+
const Demo = () => {
12+
const mounted = useUnmountPromise();
13+
useEffect(async () => {
14+
await mounted(someFunction()); // Will not resolve if component un-mounts.
15+
});
16+
};
17+
```
18+
19+
20+
## Reference
21+
22+
```ts
23+
const mounted = useUnmountPromise();
24+
25+
mounted(promise);
26+
mounted(promise, onError);
27+
```
28+
29+
- `onError` — if promise rejects after the component is unmounted, `onError`
30+
callback is called with the error.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export { default as useTitle } from './useTitle';
8585
export { default as useToggle } from './useToggle';
8686
export { default as useTween } from './useTween';
8787
export { default as useUnmount } from './useUnmount';
88+
export { default as useUnmountPromise } from './useUnmountPromise';
8889
export { default as useUpdate } from './useUpdate';
8990
export { default as useUpdateEffect } from './useUpdateEffect';
9091
export { default as useUpsert } from './useUpsert';

0 commit comments

Comments
 (0)