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

# useTemplates

> Fetch available settlement templates.

## Import

```tsx theme={null}
import { useTemplates } from '@keystoneos/react';
```

## Usage

```tsx theme={null}
function TemplateSelector({ onSelect }) {
  const { templates, isLoading } = useTemplates();

  if (isLoading) return <Spinner />;

  return (
    <select onChange={e => onSelect(e.target.value)}>
      {templates.map(t => (
        <option key={t.id} value={t.slug}>
          {t.name} - Roles: {t.config.required_roles.join(', ')}
        </option>
      ))}
    </select>
  );
}
```

## Parameters

None.

## Return Type

```typescript theme={null}
interface UseTemplatesResult {
  templates: SettlementTemplate[];
  isLoading: boolean;
  error: string | null;
  refetch: () => Promise<void>;
}
```

| Property    | Type                   | Description                    |
| ----------- | ---------------------- | ------------------------------ |
| `templates` | `SettlementTemplate[]` | Array of available templates.  |
| `isLoading` | `boolean`              | `true` during fetch.           |
| `error`     | `string \| null`       | Error message if fetch failed. |
| `refetch`   | `() => Promise<void>`  | Manually re-fetch templates.   |

### SettlementTemplate

| Property      | Type             | Description                                        |
| ------------- | ---------------- | -------------------------------------------------- |
| `id`          | `string`         | Template UUID.                                     |
| `slug`        | `string`         | URL-friendly identifier (e.g., `"dvp-bilateral"`). |
| `name`        | `string`         | Human-readable name.                               |
| `description` | `string`         | Template description.                              |
| `config`      | `TemplateConfig` | State machine definition.                          |

### TemplateConfig

| Property             | Type       | Description                                               |
| -------------------- | ---------- | --------------------------------------------------------- |
| `states`             | `string[]` | All possible states.                                      |
| `initial_state`      | `string`   | Starting state for new settlements.                       |
| `terminal_states`    | `string[]` | States that end the settlement.                           |
| `failure_states`     | `string[]` | Terminal states indicating failure.                       |
| `transitions`        | `object`   | Allowed state transitions.                                |
| `required_roles`     | `string[]` | Party roles needed (e.g., `["seller", "buyer"]`).         |
| `required_leg_types` | `string[]` | Leg types needed (e.g., `["asset_delivery", "payment"]`). |

## Behavior

* Fetches once on mount.
* Templates are global (not environment-scoped) and rarely change.
* Use `refetch()` if you need to re-check after template updates.
