Merge pull request #1574 from lmichelin/patch-1

docs: Fix useAsyncFn example to avoid error
This commit is contained in:
Anton Zinovyev 2021-04-06 11:35:17 +03:00 committed by GitHub
commit 4e07c7ebc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,7 @@ function that returns a promise. The state is of the same shape as `useAsync`.
import {useAsyncFn} from 'react-use';
const Demo = ({url}) => {
const [state, fetch] = useAsyncFn(async () => {
const [state, doFetch] = useAsyncFn(async () => {
const response = await fetch(url);
const result = await response.text();
return result
@ -23,7 +23,7 @@ const Demo = ({url}) => {
? <div>Error: {state.error.message}</div>
: <div>Value: {state.value}</div>
}
<button onClick={() => fetch()}>Start loading</button>
<button onClick={() => doFetch()}>Start loading</button>
</div>
);
};