|
Download react-use/docs/usePromise.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 534 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/usePromise.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/usePromise.md
-
curl -L -o usePromise.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/usePromise.md
534 Bytes
| # `usePromise` | |
| React Lifecycle hook that returns a helper function for wrapping promises. | |
| Promises wrapped with this function will resolve only when component is mounted. | |
| ## Usage | |
| ```jsx | |
| import {usePromise} from 'react-use'; | |
| const Demo = ({promise}) => { | |
| const mounted = usePromise(); | |
| const [value, setValue] = useState(); | |
| useEffect(() => { | |
| (async () => { | |
| const value = await mounted(promise); | |
| // This line will not execute if <Demo> component gets unmounted. | |
| setValue(value); | |
| })(); | |
| }); | |
| }; | |
| ``` | |