smart-components
Hooks

useRewrite

State machine for accept/reject rewrite flows. Streaming + LRU.

useRewrite is the engine behind SmartRewrite. Use directly when you want full control over the surrounding UI.

import { useRewrite } from '@extedcoud/smart-components';

const { rewrite, status, error, run, accept, reject } = useRewrite({
  value,
  instruction: 'Rewrite in a polished, professional tone.',
  context: 'audience is a customer support manager',
  stream: false,
  maxTokens: 512,
  temperature: 0.4,
  onAccept: (final) => setValue(final),
});

Return shape

FieldTypeDescription
rewritestringAccumulating rewrite text.
status'idle' | 'loading' | 'ready' | 'error'State machine status.
errorError | nullSet when status is error.
run(instructionOverride?: string) => voidTrigger a rewrite.
accept() => voidCalls onAccept(rewrite) and resets to idle.
reject() => voidDiscards rewrite, returns to idle.

run('...') lets you override the default instruction per call — useful for preset-button rewrites.

On this page