Skip to content

Add useProcedure React hook and export procedures from codegen#4752

Open
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson:feat/use-procedure-hook
Open

Add useProcedure React hook and export procedures from codegen#4752
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson:feat/use-procedure-hook

Conversation

@DexterKoelson
Copy link
Copy Markdown
Contributor

Closes #4751

Description of Changes

  • Add useProcedure React hook that mirrors useReducer which returns a stable, typed callback that queues calls until the connection is ready
  • Add ProcedureParamsType and ProcedureReturnType utility types to type_utils.ts
  • Update TypeScript codegen to emit export const procedures = __convertToAccessorMap(proceduresSchema.procedures) in generated module bindings, matching the existing pattern for reducers
import { procedures } from './module_bindings';
import { useProcedure } from 'spacetimedb/react';

const doSomeThing = useProcedure(procedures.doSomeThing);
const result = await doSomeThing({ foo: "..." });

API and ABI breaking changes

None. Additive only — new hook export and new codegen line.

Expected complexity level and risk

Low. The hook is a near-copy of useReducer adapted for procedure signatures. The codegen change adds one line following the identical pattern used for reducers.

Testing

  • TypeScript SDK compiles with no new errors (tsc --noEmit)
  • All 170 existing tests pass (17 test files)
  • Tested end-to-end in a React app calling a procedure

Add a useProcedure hook to the React SDK that mirrors useReducer —
queues calls until connected, returns a stable typed callback.
Also update the TypeScript codegen to emit an exported procedures
accessor map, matching the existing pattern for reducers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React SDK missing useProcedure hook and procedures accessor map

2 participants