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
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 indefineContract({ 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:
Frequently asked questions
Apps can use only the components you expose. Use tools for actions that do not describe component events.Can an app import any component from my codebase?
Can an app import any component from my codebase?
It uses generated stand-ins for the components you expose in the contract.
The client mapping keeps the real implementations outside the sandbox.
Should showing a toast be a component callback?
Should showing a toast be a component callback?
Use a client tool such as
showToast for
that action. Callbacks describe events from a rendered component, such as a
click or selection.