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

trailbase.tsx

43 lines1.1 KB

1import { createFileRoute } from '@tanstack/solid-router'
2import { useLiveQuery } from '@tanstack/solid-db'
3import {
4 trailBaseConfigCollection,
5 trailBaseTodoCollection,
6} from '../lib/collections'
7import { TodoApp } from '../components/TodoApp'
8​
9export const Route = createFileRoute(`/trailbase`)({
10 component: TrailBasePage,
11 ssr: false,
12 loader: async () => {
13 await Promise.all([
14 trailBaseTodoCollection.preload(),
15 trailBaseConfigCollection.preload(),
16 ])
17​
18 return null
19 },
20})
21​
22function TrailBasePage() {
23 // Get data using live queries with Electric collections
24 const { data: todos } = useLiveQuery((q) =>
25 q
26 .from({ todo: trailBaseTodoCollection })
27 .orderBy(({ todo }) => todo.created_at, `asc`),
28 )
29​
30 const { data: configData } = useLiveQuery((q) =>
31 q.from({ config: trailBaseConfigCollection }),
32 )
33​
34 return (
35 <TodoApp
36 todos={todos}
37 configData={configData}
38 todoCollection={trailBaseTodoCollection}
39 configCollection={trailBaseConfigCollection}
40 title="todos (TrailBase)"
41 />
42 )