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

electric.tsx

43 lines1.0 KB

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