Open History to see the last commit
1/* @refresh reload */
2import {
3 QueryClient,
4 QueryClientProvider,
5 useQuery,
6} from '@tanstack/solid-query'
7import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
8import { Loading, Match, Switch } from 'solid-js'
9import { render } from '@solidjs/web'
10β
11const queryClient = new QueryClient()
12β
13export default function App() {
14 return (
15 <QueryClientProvider client={queryClient}>
16 <SolidQueryDevtools />
17 <Loading fallback={<div>Loading...</div>}>
18 <Example />
19 </Loading>
20 </QueryClientProvider>
21 )
22}
23β
24function Example() {
25 const state = useQuery(() => ({
26 queryKey: ['repoData'],
27 queryFn: async () => {
28 const response = await fetch(
29 'https://api.github.com/repos/TanStack/query',
30 )
31 return await response.json()
32 },
33 }))
34β
35 return (
36 <Switch>
37 <Match when={state.isPending}>Loading...</Match>
38 <Match when={state.error}>
39 {'An error has occurred: ' + (state.error as Error).message}
40 </Match>
41 <Match when={state.data !== undefined}>
42 <div>
43 <h1>{state.data.name}</h1>
44 <p>{state.data.description}</p>
45 <strong>π {state.data.subscribers_count}</strong>{' '}
46 <strong>β¨ {state.data.stargazers_count}</strong>{' '}
47 <strong>π΄ {state.data.forks_count}</strong>
48 <div>{state.isFetching ? 'Updating...' : ''}</div>
49 </div>
50 </Match>
51 </Switch>
52 )
53}
54const root = document.getElementById('root')
55if (!root) throw new Error('Missing #root element')
56β
57render(() => <App />, root)