Skip to content

Commit b842dea

Browse files
docs(solid): fix and update solid query example (#124)
bumped solid-query-devtools to new version, fixed broken panel, and a little bit of re-organisation so theres less setup in the file containing the devtools panel.
1 parent e3f5fbf commit b842dea

File tree

5 files changed

+101
-60
lines changed

5 files changed

+101
-60
lines changed

docs/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@
140140
]
141141
}
142142
]
143-
}
143+
}

examples/solid/basic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
"dependencies": {
1212
"@tanstack/solid-devtools": "^0.6.6",
13-
"@tanstack/solid-query": "^5.83.0",
14-
"@tanstack/solid-query-devtools": "^5.83.0",
13+
"@tanstack/solid-query": "^5.87.1",
14+
"@tanstack/solid-query-devtools": "^5.87.1",
1515
"@tanstack/solid-router": "^1.129.8",
1616
"@tanstack/solid-router-devtools": "^1.129.8",
1717
"solid-js": "^1.9.7"

examples/solid/basic/src/index.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
import { render } from 'solid-js/web'
2-
import Devtools from './setup'
2+
// query imports
3+
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
4+
5+
// devtool imports
6+
import { TanStackDevtools } from '@tanstack/solid-devtools'
7+
import { SolidQueryDevtoolsPanel } from '@tanstack/solid-query-devtools'
8+
import { TanStackRouterDevtoolsPanel } from '@tanstack/solid-router-devtools'
9+
10+
// router implementation
11+
import Router, { router } from './setup'
12+
13+
const queryClient = new QueryClient()
314

415
function App() {
516
return (
6-
<div>
17+
<QueryClientProvider client={queryClient}>
718
<h1>TanStack Devtools Solid Basic Example</h1>
8-
<Devtools />
9-
</div>
19+
<Router />
20+
21+
<TanStackDevtools
22+
plugins={[
23+
{
24+
name: 'TanStack Query',
25+
render: <SolidQueryDevtoolsPanel />,
26+
},
27+
{
28+
name: 'TanStack Router',
29+
render: <TanStackRouterDevtoolsPanel router={router} />,
30+
},
31+
]}
32+
/>
33+
</QueryClientProvider>
1034
)
1135
}
1236

examples/solid/basic/src/setup.tsx

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
2-
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
3-
import { TanStackRouterDevtoolsPanel } from '@tanstack/solid-router-devtools'
1+
import { Match, Switch } from 'solid-js'
2+
// query imports
3+
import { useQuery } from '@tanstack/solid-query'
4+
5+
// router imports
46
import {
57
Link,
68
Outlet,
@@ -9,15 +11,15 @@ import {
911
createRoute,
1012
createRouter,
1113
} from '@tanstack/solid-router'
12-
import { TanStackDevtools } from '@tanstack/solid-devtools'
1314

1415
const rootRoute = createRootRoute({
1516
component: () => (
1617
<>
1718
<div class="p-2 flex gap-2">
1819
<Link to="/" class="[&.active]:font-bold">
1920
Home
20-
</Link>{' '}
21+
</Link>
22+
2123
<Link to="/about" class="[&.active]:font-bold">
2224
About
2325
</Link>
@@ -28,57 +30,62 @@ const rootRoute = createRootRoute({
2830
),
2931
})
3032

33+
/*
34+
/ demo route
35+
*/
3136
const indexRoute = createRoute({
3237
getParentRoute: () => rootRoute,
3338
path: '/',
3439
component: function Index() {
40+
/*
41+
/ demo query resolves after three seconds and returns string
42+
*/
43+
const exampleQuery = useQuery<string>(() => ({
44+
queryKey: ['example-query'],
45+
queryFn: () => {
46+
return new Promise((resolve) => {
47+
setTimeout(() => {
48+
resolve('fetched data')
49+
}, 3000)
50+
})
51+
},
52+
}))
53+
3554
return (
3655
<div class="p-2">
3756
<h3>Welcome Home!</h3>
57+
<Switch>
58+
<Match when={exampleQuery.isLoading}>
59+
<p>Loading...</p>
60+
</Match>
61+
62+
<Match when={exampleQuery.data}>
63+
<p>{exampleQuery.data}</p>
64+
</Match>
65+
</Switch>
3866
</div>
3967
)
4068
},
4169
})
42-
function About() {
43-
return (
44-
<div class="p-2">
45-
<h3>Hello from About!</h3>
46-
</div>
47-
)
48-
}
4970

71+
/*
72+
/ demo route
73+
*/
5074
const aboutRoute = createRoute({
5175
getParentRoute: () => rootRoute,
5276
path: '/about',
53-
component: About,
77+
component: function About() {
78+
return (
79+
<div class="p-2">
80+
<h3>Hello from About!</h3>
81+
</div>
82+
)
83+
},
5484
})
5585

5686
const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
87+
export const router = createRouter({ routeTree })
5788

58-
const router = createRouter({ routeTree })
59-
60-
const queryClient = new QueryClient()
61-
62-
export default function DevtoolsExample() {
63-
return (
64-
<>
65-
<TanStackDevtools
66-
plugins={[
67-
{
68-
name: 'TanStack Query',
69-
render: (
70-
<QueryClientProvider client={queryClient}>
71-
<SolidQueryDevtools />
72-
</QueryClientProvider>
73-
),
74-
},
75-
{
76-
name: 'TanStack Router',
77-
render: <TanStackRouterDevtoolsPanel router={router} />,
78-
},
79-
]}
80-
/>
81-
<RouterProvider router={router} />
82-
</>
83-
)
89+
export default function Router() {
90+
return <RouterProvider router={router} />
8491
}

pnpm-lock.yaml

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)