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.
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
- 01Read the app runtime
Send only events that your app knows happened.
- 02Register existing elements
Ref bindings track focus and visibility without changing markup or styles.
- 03Expose 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.
| Property | Target | Purpose |
|---|---|---|
| composerProps | HTMLTextAreaElement | Detects focus in the composer |
| conversationProps | HTMLElement | Detects focus in conversation history |
| newestResponseProps | HTMLElement | Checks whether the newest response is visible |