> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Views and elements

> View states from @bijectionhq/bijection/react, drawn by the registry's elements

The SDK owns the data and the [registry](https://ui.bijection.com) owns the
drawing. `@bijectionhq/bijection/react` answers each read and mutation as the
state a view draws; domain libraries ship no React components.

## Install registry elements

Elements are presentation-only shadcn components for Bijection subjects
(conversations, tool calls, requests, reviews, deliveries, workflow runs,
datasets, files, notifications, documents, agents, automations, alerts,
connections, extraction, sign-in and account management). Register the
`@bijection` namespace once in a shadcn project, then add the elements you
need:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npx shadcn@latest registry add @bijection=https://ui.bijection.com/r/{name}.json
npx shadcn@latest add @bijection/<name>
```

Each element imports nothing from `bijection` or `@bijectionhq/*`. It declares
the plain prop shapes it renders and reports user actions through callbacks
(`onSend`, `onReview`, `onApprove`). Your app loads live data with the SDK
hooks below, maps its facts onto those props, and wires callbacks to mutations.

## View hooks in `@bijectionhq/bijection/react`

| Hook | Answers |
| - | - |
| `refusalText(refusal)` from `@bijectionhq/bijection/client` | Shows the refusal's message, including a `Forbidden` message from `forbid`. It uses generic text for `Disallowed`, `Unknown` and `Failed`. |

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, mutation, query, role, t, table } from "@bijectionhq/bijection";

const accounting = label();
const collector = role({ clear: [accounting] });
const items = table({ number: t.string, collector: t.maybe(t.principal) }, {
  label: accounting, index: [["collector"]],
});
const open = query({ under: accounting, allow: [collector] }, (ctx) =>
  ctx.list(items.where({ collector: null }).first(50)),
);
const assign = mutation(
  { under: accounting, allow: [collector], args: { invoice: t.key(items) }, refuses: { AlreadyAssigned: null } },
  async (ctx, { invoice }) => {
    const item = await ctx.get(items(invoice));
    if (item === null) return ctx.refuse("Absent", "Invoice not found");
    if (item.collector !== null) return ctx.refuse("AlreadyAssigned", "Someone already took this invoice");
    await ctx.patch(items(invoice), { collector: ctx.frame.as.id });
  },
);

export default app({ accounting, collector, invoices: { items, open, assign } });
```

```tsx src/Invoices.tsx theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { api, connect } from "@bijectionhq/bijection/client";
import { refusalText } from "@bijectionhq/bijection/client";
import { Bijection, useMutation, useWatch } from "@bijectionhq/bijection/react";
import type App from "../bijection/app";

const app = api<typeof App>();
const client = connect("https://example.bijection.cloud", { contract: "discover" }).under(app.accounting);

function OpenInvoices() {
  const invoices = useWatch(app.invoices.open, {});
  const assign = useMutation(app.invoices.assign);
  if (invoices === undefined) return <p role="status">Loading…</p>;
  if (!invoices.ok) return <p role="alert">{refusalText(invoices)}</p>;
  return (
    <ul>
      {invoices.value.map((fact) => (
        <li key={fact.id}>
          {fact.number}
          <button disabled={assign.pending} onClick={() => void assign({ invoice: fact.id })}>Take</button>
        </li>
      ))}
      {assign.last?.ok === false ? <p role="alert">{refusalText(assign.last)}</p> : null}
    </ul>
  );
}

export function Invoices() {
  return (
    <Bijection client={client}>
      <OpenInvoices />
    </Bijection>
  );
}
```

The hooks add no authority: each function's `allow`, labels and guards
decide what the reader sees and may do. Keep the arguments you pass stable,
at module scope or with `useMemo`, because a watch starts again when their
value changes.

The registry's `file-bytes` element includes `useExactFile` to read
a citation's bytes through the app's protected delivery route and check its
size and SHA-256. `readExactFile` performs the same read outside React.

Place this component next to the installed `file-bytes-read.ts` helper.

```tsx cited-file.tsx theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import type { ComponentType } from "react";
import type { File } from "@bijectionhq/bijection";
import { useExactFile, type ExactFileState, type ReadFile } from "./file-bytes-read";

type Citation = { id: File; size: number; sha256: string; mediaType: string; name: string };
type FileBytesProps = {
  status: ExactFileState["status"];
  bytes?: Uint8Array;
  error?: string;
  mediaType: string;
  size: number;
  label: string;
};

export function CitedFile({ FileBytes, read, cited }: {
  FileBytes: ComponentType<FileBytesProps>;
  read: ReadFile | null;
  cited: Citation;
}) {
  const file = useExactFile(read, cited.id.id, { size: cited.size, sha256: cited.sha256 });
  return (
    <FileBytes
      status={file.status}
      {...(file.status === "ready" ? { bytes: file.bytes } : {})}
      {...(file.status === "failed" ? { error: file.message } : {})}
      mediaType={cited.mediaType}
      size={cited.size}
      label={cited.name}
    />
  );
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.