forked from TanStack/db
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.tsx
More file actions
40 lines (35 loc) · 1019 Bytes
/
query.tsx
File metadata and controls
40 lines (35 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { createFileRoute } from "@tanstack/solid-router"
import { useLiveQuery } from "@tanstack/solid-db"
import { queryConfigCollection, queryTodoCollection } from "../lib/collections"
import { TodoApp } from "../components/TodoApp"
export const Route = createFileRoute(`/query`)({
component: QueryPage,
ssr: false,
loader: async () => {
await Promise.all([
queryTodoCollection.preload(),
queryConfigCollection.preload(),
])
return null
},
})
function QueryPage() {
// Get data using live queries with Query collections
const { data: todos } = useLiveQuery((q) =>
q
.from({ todo: queryTodoCollection })
.orderBy(({ todo }) => todo.created_at, `asc`)
)
const { data: configData } = useLiveQuery((q) =>
q.from({ config: queryConfigCollection })
)
return (
<TodoApp
todos={todos}
configData={configData}
todoCollection={queryTodoCollection}
configCollection={queryConfigCollection}
title="todos (query)"
/>
)
}