Skip to content

Reactivity system

LiveStore provides a Signals-like reactivity system which supports:

  • Reactive SQL queries on top of SQLite state (queryDb())
  • Reactive computed values (computed())
  • Reactive state values (makeRef())

Live query variables end on a $ by convention (e.g. todos$).

Reactive SQL queries

import { queryDb } from '@livestore/livestore'
const todos$ = queryDb(tables.todos.orderBy('createdAt', 'desc'))
// Or using callback syntax to depend on other queries
const todos$ = queryDb((get) => {
const { showCompleted } = get(uiState$)
return tables.todos.where(showCompleted ? { completed: true } : {})
})

Computed values

import { computed } from '@livestore/livestore'
const showAllLabel$ = computed((get) => get(uiState$).showCompleted ? 'show completed' : 'show all')

Further reading

  • Signia: Signia is a minimal, fast, and scalable signals library for TypeScript developed by TLDraw.