Skip to main content
Apps run in a sandbox, without direct access to your components or the surrounding page. A component schema describes what they can use: its props, events, and children. Patchsmith generates stand-in components for the sandbox. A local bridge passes UI updates to your real components and sends events back to app code. Updates cross this bridge in the browser without a server round trip.

Define a component

A button shows a component schema with behavior guidance:
patchsmith.ts

Connect the real component

Map the schema’s name to your existing button when you create the client:
patchsmith-client.tsx
A callback describes an event on a component. For an action such as opening a toast or navigating, expose a client tool instead. See Write app UI for using these components in an app.

Change a component schema

Removing a field, an allowed variant such as "secondary", or a callback can break apps that use it. Adding a required field can break them too. Prefer optional additions and keep existing names and values until those apps have migrated.

SDK reference

Each entry in defineContract({ components }) describes one component. Schema means a Standard Schema validator, such as Zod. A callback can declare input for its event payload and output for its result. Its app implementation can return the result directly or return a promise. {} declares no arguments and a void | Promise<void> app return type. Host callbacks always return promises because results cross the sandbox bridge. Await the result in your host component:
Callbacks cannot supply an immediate return value to a host API that requires a synchronous result. Callback exceptions and rejected promises reject the host promise. Pending calls reject when the sandbox closes or after 30 seconds without a result.

Frequently asked questions

Apps can use only the components you expose. Use tools for actions that do not describe component events.
It uses generated stand-ins for the components you expose in the contract. The client mapping keeps the real implementations outside the sandbox.
Use a client tool such as showToast for that action. Callbacks describe events from a rendered component, such as a click or selection.