Open History to see the last commit
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({
26 query: (q) =>
27 q
28 .from({ todo: trailBaseTodoCollection })
29 .orderBy(({ todo }) => todo.created_at, `asc`),
30 })
31
32 const { data: configData } = useLiveQuery({
33 query: (q) => q.from({ config: trailBaseConfigCollection }),
34 })
35
36 // Note: TrailBase collections use recordApi internally, which is not exposed
37 // as a collection utility. For this example, we're not using serialized
38 // transactions with TrailBase - the color picker will use naked collection
39 // calls which invoke the collection's built-in handlers automatically.
40 // In a real app, you could expose the recordApi via utils to enable
41 // serialized transactions with TrailBase collections.
42
43 return (
44 <TodoApp
45 todos={todos}
46 configData={configData}
47 todoCollection={trailBaseTodoCollection}
48 configCollection={trailBaseConfigCollection}
49 title="todos (TrailBase)"
50 />
51 )
52}