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