typescript-client

Implements SpacetimeDB TypeScript and React client connections with subscriptions and reducers.

25.1k|1.1k|Updated Jun 17, 2023
One-click install
npx skills add https://github.com/clockworklabs/SpacetimeDB --skill typescript-client
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-client
Source: https://github.com/clockworklabs/SpacetimeDB/tree/main/codex-plugin/plugins/spacetimedb/skills/typescript-client
Command: npx skills add https://github.com/clockworklabs/SpacetimeDB --skill typescript-client

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires spacetimedb.

What problem does it solve?

Building web clients that connect to SpacetimeDB requires knowing the correct patterns for connection setup, table subscriptions, reducer calls, and React hooks, and mistakes like mutating readonly rows or rendering bigint values cause confusing failures.

Core Features & Use Cases

  • React Integration: Set up SpacetimeDBProvider, useSpacetimeDB, and useTable hooks with typed query builders and row callbacks for insert, delete, and update events.
  • Vanilla TypeScript Clients: Build non-React connections using DbConnection.builder with onConnect handlers and subscription builders.
  • Gotcha Prevention: Handle readonly useTable rows by copying before sorting, and wrap bigint values from u64/i64 columns with Number() or String() for JSX rendering.
  • Use Case: You are building a React dashboard backed by a SpacetimeDB module and need to subscribe to filtered tables, react to row changes, and call reducers with object syntax.

Quick Start

Use the typescript-client skill to scaffold a React app that connects to my SpacetimeDB module and subscribes to its tables.

Frequently Asked Questions about typescript-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I connect a React app to SpacetimeDB?

Wrap your app in SpacetimeDBProvider from spacetimedb/react with a connection builder created via DbConnection.builder().withUri().withDatabaseName(). Then use the useSpacetimeDB and useTable hooks inside child components to access the connection and subscribe to tables.

How do I subscribe to SpacetimeDB tables in TypeScript?

Use conn.subscriptionBuilder().onApplied(callback).subscribe() with an array of table references like tables.entity. You can filter with typed query builders such as tables.entity.where(r => r.active.eq(true)) or pass raw SQL strings.

Can I use the SpacetimeDB client without React?

Yes, the vanilla TypeScript API works without React. Build a connection with DbConnection.builder(), register an onConnect handler for subscriptions, and attach row callbacks via conn.db.table.onInsert, onDelete, and onUpdate.

Why does sorting useTable rows fail in TypeScript?

Rows returned by useTable are readonly, so in-place array methods like sort fail type-checking. Copy the array first with the spread operator, for example const sorted = [...rows].sort(...), before mutating.

Why does React fail to render SpacetimeDB row IDs?

Columns defined as t.u64() or t.i64() map to JavaScript bigint, which React cannot render directly in JSX. Convert the value with Number(row.id) or String(count) before rendering.