Skip to main content

Import

import { useTemplates } from '@keystoneos/react';

Usage

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

interface UseTemplatesResult {
  templates: SettlementTemplate[];
  isLoading: boolean;
  error: string | null;
  refetch: () => Promise<void>;
}
PropertyTypeDescription
templatesSettlementTemplate[]Array of available templates.
isLoadingbooleantrue during fetch.
errorstring | nullError message if fetch failed.
refetch() => Promise<void>Manually re-fetch templates.

SettlementTemplate

PropertyTypeDescription
idstringTemplate UUID.
slugstringURL-friendly identifier (e.g., "dvp-bilateral").
namestringHuman-readable name.
descriptionstringTemplate description.
configTemplateConfigState machine definition.

TemplateConfig

PropertyTypeDescription
statesstring[]All possible states.
initial_statestringStarting state for new settlements.
terminal_statesstring[]States that end the settlement.
failure_statesstring[]Terminal states indicating failure.
transitionsobjectAllowed state transitions.
required_rolesstring[]Party roles needed (e.g., ["seller", "buyer"]).
required_leg_typesstring[]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.