Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

app.tsx

36 lines831 Bytes

1import {
2 QueryClient,
3 QueryClientProvider,
4 useQuery,
5} from '@tanstack/solid-query'
6import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
7import { Match, Switch } from 'solid-js'
8​
9const Example = () => {
10 const query = useQuery(() => ({
11 queryKey: ['test'],
12 queryFn: async () => {
13 await new Promise((r) => setTimeout(r, 1000))
14 return 'Success'
15 },
16 }))
17​
18 return (
19 <Switch>
20 <Match when={query.isPending}>Loading...</Match>
21 <Match when={query.isError}>An error has occurred!</Match>
22 <Match when={query.isSuccess}>{query.data}</Match>
23 </Switch>
24 )
26​
27export default function App() {
28 const queryClient = new QueryClient()
29​
30 return (
31 <QueryClientProvider client={queryClient}>
32 <SolidQueryDevtools />
33 <Example />
34 </QueryClientProvider>
35 )