Docs · Hooks & Helpers

Hooks & Helpers

The developer-experience layer: a state hook, trigger preset factories, and segment helpers that remove boilerplate.

usePromptAreaState()

Manages the segment value, ref, and derived state. Call it once and spread bind onto the component.

const { bind, plainText, isEmpty, hasChips, chips, clear, focus } =
  usePromptAreaState()

<PromptArea {...bind} />
PropTypeDefaultDescription
bind{ ref, value, onChange }Spread onto <PromptArea {...bind} />.
plainTextstringDerived plain text of the current value.
isEmptybooleanTrue when empty or whitespace-only.
hasChipsbooleanTrue when the value contains a chip.
chipsChipSegment[]All chip segments in the value.
clear()() => voidClear all content.
focus() / blur()() => voidFocus or blur the input.
insertChip()(chip: Omit<ChipSegment, 'type'>) => voidInsert a chip imperatively.

Trigger presets

Each returns a TriggerConfig for the triggers prop. Pass onSearch to supply items, plus optional styling.

PropTypeDefaultDescription
mentionTrigger(opts?)(opts) => TriggerConfig@ dropdown for users, agents, or documents.
commandTrigger(opts?)(opts) => TriggerConfig/ dropdown with start-of-line detection.
hashtagTrigger(opts?)(opts) => TriggerConfig# tags that auto-resolve on space.
callbackTrigger(opts)(opts) => TriggerConfigFire a callback (e.g. file picker) instead of a dropdown.

Segment helpers

Pure functions for building and reading segment arrays:

PropTypeDefaultDescription
text(value)(string) => TextSegmentCreate a text segment.
chip(opts)(Omit<ChipSegment,'type'>) => ChipSegmentCreate a chip segment.
getChips(segments)(Segment[]) => ChipSegment[]All chips in a segment array.
getChipsByTrigger(segments, trigger)(Segment[], string) => ChipSegment[]Chips for one trigger, e.g. '@' or '/'.
isSegmentsEmpty(segments)(Segment[]) => booleanTrue when empty or whitespace-only.
hasChips(segments)(Segment[]) => booleanTrue when at least one chip is present.
import { getChipsByTrigger } from '@/components/segment-helpers'

const mentions = getChipsByTrigger(bind.value, '@').map((c) => c.value)