-
-
Save brunosabot/85be602e84f539e04c0d56eaba8893a8 to your computer and use it in GitHub Desktop.
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
import { QueryClient, QueryClientProvider, useQuery } from "react-query"; | |
const queryClient = new QueryClient(); | |
export default function App() { | |
return ( | |
<QueryClientProvider client={queryClient}> | |
<MyRenderingComponent /> | |
</QueryClientProvider> | |
); | |
} | |
function MyRenderingComponent() { | |
const { isLoading, error, data } = useQuery("apiHello", () => | |
fetch("https://brunosabot.dev/api/hello/").then((res) => res.json()) | |
); | |
if (isLoading) return <div>Loading...</div>; | |
if (error) return <div>An error has occurred</div>; | |
return <div>{data.name}</div>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment