useState but typed & w/ reactive queries
const { collection: peopleCollection, insert } = useLocalCollection({
getId: (item) => item.id,
initial: [
{ name: `bob`, id: crypto.randomUUID(), age: 47 },
{ name: `jane`, id: crypto.randomUUID(), age: 25 }
]
})
const { data: youngerThan40 } = useLiveQuery(q => q.from({ peopleCollection }).filter(`@age`, `<`, 40))
// Unlike other collections, you can use this outside of a transaction because it
// doesn't need persisted anywhere (it'd also work inside transactions).
insert({ id: crypto.randomUUID(), name: `Louie`, age: 34 })
Perhaps a single-value variant would be useful too. Avoid the need for arrays & an id then.