Last active
June 7, 2021 12:55
-
-
Save ashimon83/52fbd19a877d3b9ea88e1f5c380dca2e to your computer and use it in GitHub Desktop.
fetch with hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ComponentWithUseFetch = () => { | |
const { data, isLoading, hasError, errorMessage, refetch } = useFetch<{ name: string }>({ | |
url: '/api/someone/123', | |
skip: true | |
}) | |
if (isLoading) { | |
return <Loader /> | |
} | |
return ( | |
<> | |
<div> | |
{data ? `Hello ${data.name} !` : 'please click button'} | |
</div> | |
{hasError && <b>{errorMessage}</b>} | |
<button onClick={() => refetch()}>call user name</button> | |
</> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment