Skip to content

Instantly share code, notes, and snippets.

@ashimon83
Last active June 8, 2021 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashimon83/a0d7903d1d711d6bc407e285e10c25fc to your computer and use it in GitHub Desktop.
Save ashimon83/a0d7903d1d711d6bc407e285e10c25fc to your computer and use it in GitHub Desktop.
const ComponentWithUseFetch = () => {
const { data, isLoading, hasError, errorMessage } = useFetch<{ name: string }>({
url: '/api/someone/123'
})
if (isLoading) {
return <Loader />
}
return (
<>
<div>
Hello {data?.name} !
</div>
{hasError && <b>{errorMessage}</b>}
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment