Created
September 29, 2025 18:32
-
-
Save RafalFilipek/c7fe4cb030ba7223966791789b170136 to your computer and use it in GitHub Desktop.
Untitled Project
This file contains hidden or 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 { useQuery, QueryClientProvider, QueryClient } from "react-query"; | |
| import useSWR, { SWRConfig } from 'use-swr' | |
| const queryClient = new QueryClient(); | |
| export default function Application({ children }) { | |
| return ( | |
| <SWRConfig value={{}}> | |
| <QueryClientProvider client={queryClient}> | |
| <App /> | |
| </QueryClientProvider> | |
| </SWRConfig> | |
| ); | |
| } | |
| function App() { | |
| const q = useQuery(["todos"], { | |
| refetchOnWindowFocus: false, | |
| initialData: 2, | |
| queryFn: async () => { | |
| const r = await fetch("https://jsonplaceholder.typicode.com/todos/"); | |
| return r.json(); | |
| }, | |
| }); | |
| const r = useSWR('todos', { | |
| refetchOnWindowFocus: false, | |
| initialData: 2, | |
| fetcher: async () => { | |
| const r = await fetch("https://jsonplaceholder.typicode.com/todos/"); | |
| return r.json(); | |
| }, | |
| }); | |
| {r.} | |
| return ( | |
| <div className="grid grid-cols-2"> | |
| <div> | |
| <h2 className="text-xl font-bold">React Query</h2> | |
| {q.isLoading ? "Loading..." : "Loaded"} | |
| <hr /> | |
| {q.isFetched ? "Fetched" : "Not fetched"} | |
| <hr /> | |
| {q.status} | |
| <hr /> | |
| {q.isRefetching ? "Refetching" : "Not refetching"} | |
| <hr /> | |
| <button onClick={() => q.refetch()}>Refetch</button> | |
| </div> | |
| <div> | |
| <h2 className="text-xl font-bold">SWR</h2> | |
| {r.is ? "Loading..." : "Loaded"} | |
| <hr /> | |
| {q.isFetched ? "Fetched" : "Not fetched"} | |
| <hr /> | |
| {q.status} | |
| <hr /> | |
| {q.isRefetching ? "Refetching" : "Not refetching"} | |
| <hr /> | |
| <button onClick={() => q.refetch()}>Refetch</button> | |
| </div> | |
| </div> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment