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

trailbase.tsx

51 lines1.5 KB

1import * as React from 'react'
2import { createFileRoute } from '@tanstack/react-router'
3import { useLiveQuery } from '@tanstack/react-db'
4import {
5 trailBaseConfigCollection,
6 trailBaseTodoCollection,
7} from '../lib/collections'
8import { TodoApp } from '../components/TodoApp'
9​
10export const Route = createFileRoute(`/trailbase`)({
11 component: TrailBasePage,
12 ssr: false,
13 loader: async () => {
14 await Promise.all([
15 trailBaseTodoCollection.preload(),
16 trailBaseConfigCollection.preload(),
17 ])
18​
19 return null
20 },
21})
22​
23function TrailBasePage() {
24 // Get data using live queries with TrailBase collections
25 const { data: todos } = useLiveQuery((q) =>
26 q
27 .from({ todo: trailBaseTodoCollection })
28 .orderBy(({ todo }) => todo.created_at, `asc`),
29 )
30​
31 const { data: configData } = useLiveQuery((q) =>
32 q.from({ config: trailBaseConfigCollection }),
33 )
34​
35 // Note: TrailBase collections use recordApi internally, which is not exposed
36 // as a collection utility. For this example, we're not using serialized
37 // transactions with TrailBase - the color picker will use naked collection
38 // calls which invoke the collection's built-in handlers automatically.
39 // In a real app, you could expose the recordApi via utils to enable
40 // serialized transactions with TrailBase collections.
41​
42 return (
43 <TodoApp
44 todos={todos}
45 configData={configData}
46 todoCollection={trailBaseTodoCollection}
47 configCollection={trailBaseConfigCollection}
48 title="todos (TrailBase)"
49 />
50 )