Skip to content

Add LocalCollection / useLocalCollection / createLocalCollection #79

@KyleAMathews

Description

@KyleAMathews

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions