React Package
@kalamdb/react adds React hooks and render-prop components for KalamDB live rows. Use it when a React app needs realtime tables, typed mutations, or a screen with many live datasets.
Install
@kalamdb/orm and drizzle-orm are needed for typed table mode. Raw SQL mode only needs @kalamdb/react and @kalamdb/client.
What It Adds
| Export | Type | Use it for |
|---|---|---|
KalamProvider | component | Put one KalamDB client in React context. |
LiveQuery | component | Render one live query with typed rows or raw SQL rows. |
LiveQueries | component | Render several named live queries together. |
useKalamClient | hook | Read the client from context, or pass one directly. |
useLiveQuery | hook | Read one live query and call insert, update, remove, or refetch. |
useLiveQueries | hook | Read several Drizzle live queries with one aggregate state. |
useLiveSelection | hook | Derive view data from live rows. |
useMutationState | hook | Track local insert, update, delete, and error state. |
useMutationActions | hook | Use mutation helpers without opening a live query. |
The live query context includes rows, state, insert, update, remove, clearError, and refetch. state.updating and state.deleting are Set<string | number> values keyed by row id.
App Setup
Create one client and wrap your app.
Typed Table Schema
Use kTable.user(...) when you want typed rows and typed mutation payloads.
One Live Query
LiveQuery is the simplest UI component. The child receives rows, connection state, mutation state, and mutation helpers.
Use deps when a query depends on props or state. The live controller restarts when those values change.
Hook Form
useLiveQuery returns the same context without a render-prop wrapper.
Use select when a component only needs derived data.
Raw SQL Mode
Raw SQL mode is useful for simple views that do not use Drizzle tables. Rows are RowData, so convert cell values before rendering.
Use getKey when the row key is not obvious, or when the query returns a computed key.
Many Live Queries
LiveQueries and useLiveQueries open one controller per named query. The aggregate state is useful for dashboards and assistant screens.
Assistant Screen Pattern
The newest package example uses named datasets for messages, tool calls, tool results, typing, presence, and approvals.
Mutation Helpers
Mutations work with typed tables or string table names.
For typed tables, camel-case keys map to database column names and Drizzle encoders run before the payload is sent.
Examples
Package Examples
The React package includes small source examples in link/sdks/typescript/react/example:
messages-pane.tsx: typedLiveQuerywith insert state.sql-messages-pane.tsx: raw SQLLiveQuerywithgetKey.assistant-workspace.tsx:useLiveQueriesplususeLiveSelectionfor messages, tools, results, typing, presence, and approvals.
React AI Chat App
The main runnable example is examples/react-ai-chat. It shows KalamProvider, LiveQueries, conversation navigation, message history, file attachments, streamed typing tokens, final assistant inserts, and approval actions.
Open the Vite URL, usually http://127.0.0.1:5176.
For browser-only demo mode, skip npm run setup and set this in .env.local:
Validate the example:
Read next: TypeScript Examples and Drizzle ORM & Generator.