Skip to main content
An app supplies UI for the slots in its contract. A view defines what to show in a slot for a particular context. These examples assume your app is configured to use that contract. Generate its bindings after adding or changing capabilities:

Write a view

Put view files in src/slots/<slot>/ with a .view.tsx suffix. This view supplies default UI for the panel slot:
src/slots/panel/index.view.tsx
The folder identifies the slot. The filename identifies the context: index.view.tsx maps to /, and members/detail.view.tsx or members.detail.view.tsx maps to /members/detail. An explicit view gives useContext() its inferred type and must match that path. The build rejects mismatched view or slot declarations.

Use components and tools

Add another view for /members/detail. With Button and showToast exposed in the contract, generated imports let you use them together:
src/slots/panel/members.detail.view.tsx
On a member’s page, Patchsmith selects this view and supplies the member context. Elsewhere, the panel can fall back to the overview. The button’s click callback calls a client tool that shows a toast.

Supply several instances

For a tile slot declared with multiple: true, return an entry for each dashboard tile:
src/slots/tile/index.view.tsx
resolve runs on the app server. It can use the current context and registered queries to load entries. useInstance() reads the selected entry in the UI. The surrounding dashboard decides how to use position metadata. For a repeatable page slot, use the same pattern with keys such as reports and activity, and metadata such as { label: "Reports", icon: "chart" } for sidebar links.

SDK reference

Import defineView from patchsmith/client. The build discovers .view.tsx files and extracts instance resolvers into the server bundle. The resolver receives { context, identity, signal, queries }. It can call registered queries; actions and mutations are unavailable there. Each entry needs a stable, non-empty key unique within its view, a metadata object, and data matching dataSchema. Use metadata for labels or placement hints and data for values the view renders:
view.useInstance() reads the selected entry, with its data type inferred from dataSchema.

Frequently asked questions

View filenames determine context paths. Instance metadata describes labels and placement; instance data supplies rendered values.
Yes. index.view.tsx produces /; members/index.view.tsx produces /members. Explicit view values must agree with the file path. Only .view.tsx files register views.
Return labels, icons, or placement hints in metadata. The surrounding UI uses them to build links or arrange tiles. Put values your view needs to render in data.