|
Download react-use/docs/useUnmountPromise.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 617 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useUnmountPromise.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useUnmountPromise.md
-
curl -L -o useUnmountPromise.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useUnmountPromise.md
617 Bytes
| # `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. | |