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