mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
docs: ✏️ add useUnmountedPromise reference
This commit is contained in:
parent
797e54c33b
commit
28ef34b4c7
@ -111,7 +111,7 @@
|
||||
- [`useMountedState`](./docs/useMountedState.md) — track if component is mounted.
|
||||
- [`usePromise`](./docs/usePromise.md) — resolves promise only while component is mounted.
|
||||
- [`useLogger`](./docs/useLogger.md) — logs in console as component goes through life-cycles.
|
||||
- [`useMount`](./docs/useMount.md) — calls `mount` callbacks.
|
||||
- [`useMount`](./docs/useMount.md) and [`useUnmountPromise`](./docs/useUnmountPromise.md) — tracks if component is mounted.
|
||||
- [`useUnmount`](./docs/useUnmount.md) — calls `unmount` callbacks.
|
||||
- [`useUpdateEffect`](./docs/useUpdateEffect.md) — run an `effect` only on updates.
|
||||
- [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that does not show warning when server-side rendering.
|
||||
|
||||
30
docs/useUnmountPromise.md
Normal file
30
docs/useUnmountPromise.md
Normal file
@ -0,0 +1,30 @@
|
||||
# `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.
|
||||
@ -85,6 +85,7 @@ export { default as useTitle } from './useTitle';
|
||||
export { default as useToggle } from './useToggle';
|
||||
export { default as useTween } from './useTween';
|
||||
export { default as useUnmount } from './useUnmount';
|
||||
export { default as useUnmountPromise } from './useUnmountPromise';
|
||||
export { default as useUpdate } from './useUpdate';
|
||||
export { default as useUpdateEffect } from './useUpdateEffect';
|
||||
export { default as useUpsert } from './useUpsert';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user