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

electric.tsx

46 lines1.1 KB

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