Open History to see the last commit
1// The typical app, plus a live query that groups and counts.
2import { count } from '@tanstack/db'
3import { useLiveQuery } from '@tanstack/react-db'
4import { todos } from './app.js'
5
6export * from './app.js'
7
8export function TodosPerUser() {
9 const { data } = useLiveQuery((q) =>
10 q
11 .from({ todo: todos })
12 .groupBy(({ todo }) => todo.userId)
13 .select(({ todo }) => ({ userId: todo.userId, total: count(todo.id) })),
14 )
15 return data
16}