|
Download react-use/docs/useAsyncRetry.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 719 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useAsyncRetry.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useAsyncRetry.md
-
curl -L -o useAsyncRetry.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useAsyncRetry.md
719 Bytes
| # `useAsyncRetry` | |
| Uses `useAsync` with an additional `retry` method to easily retry/refresh the async function; | |
| ## Usage | |
| ```jsx | |
| import {useAsyncRetry} from 'react-use'; | |
| const Demo = ({url}) => { | |
| const state = useAsyncRetry(async () => { | |
| const response = await fetch(url); | |
| const result = await response.text(); | |
| return result; | |
| }, [url]); | |
| return ( | |
| <div> | |
| {state.loading | |
| ? <div>Loading...</div> | |
| : state.error | |
| ? <div>Error: {state.error.message}</div> | |
| : <div>Value: {state.value}</div> | |
| } | |
| {!loading && <button onClick={() => state.retry()}>Start loading</button>} | |
| </div> | |
| ); | |
| }; | |
| ``` | |
| ## Reference | |
| ```ts | |
| useAsyncRetry(fn, args?: any[]); | |
| ``` | |