React

React hooks

React hooks for the runtime, attention, preferences, and refs for existing app elements.

Bind an existing chat interface

Bindings contain refs only. Add them to semantic elements already in your app.

tsx
function ExistingChat() {
  const runtime = useGenerativeA11yRuntime();
  const attention = useGenerativeA11yAttention();
  const { preferences, setPreferences } = useGenerativeA11yPreferences();
  const bindings = useGenerativeA11yBindings();

  return (
    <main {...bindings.conversationProps}>
      <article {...bindings.newestResponseProps}>Latest response</article>
      <textarea {...bindings.composerProps} />
      <button onClick={() => runtime.dispatch(startEvent)}>Send</button>
      <output>{attention.mode}</output>
      <button onClick={() => setPreferences({ ...preferences, streaming: "less" })}>
        Reduce streaming detail
      </button>
    </main>
  );
}

How this code works

  1. 01
    Read the app runtime

    Send only events that your app knows happened.

  2. 02
    Register existing elements

    Ref bindings track focus and visibility without changing markup or styles.

  3. 03
    Expose user control

    Preference updates remain validated and versioned.

Options and return values

useGenerativeA11y()GenerativeA11yContextValueHook

Returns runtime, attentionStore, and preferenceStore from the nearest provider.

Default
n/a
useGenerativeA11yRuntime()GenerativeA11yRuntimeHook

Returns the provider runtime.

Default
n/a
useGenerativeA11yAttention()AttentionSnapshotHook

Uses useSyncExternalStore to report browser focus and visibility without guessing missing values.

Default
unknown SSR snapshot
useGenerativeA11yPreferences()GenerativeA11yPreferencesResultHook

Returns validated preferences, setPreferences, and the underlying store.

Default
n/a
useGenerativeA11yBindings()GenerativeA11yBindingsHook

Returns stable composer, conversation, and newest-response ref props.

Default
n/a

GenerativeA11yBindings

Each property contains a React ref for an existing part of your interface.

PropertyTargetPurpose
composerPropsHTMLTextAreaElementDetects focus in the composer
conversationPropsHTMLElementDetects focus in conversation history
newestResponsePropsHTMLElementChecks whether the newest response is visible