Skip to content

Instantly share code, notes, and snippets.

@brunosabot
Created January 29, 2022 21:46
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 brunosabot/85be602e84f539e04c0d56eaba8893a8 to your computer and use it in GitHub Desktop.
Save brunosabot/85be602e84f539e04c0d56eaba8893a8 to your computer and use it in GitHub Desktop.
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