Skip to content

@askable-ui/react

React bindings for askable-ui. Requires React 17+.

Install

bash
npm install @askable-ui/react @askable-ui/core

<Askable>

Renders a wrapper element with data-askable managed reactively from the meta prop.

tsx
import { Askable } from '@askable-ui/react';

<Askable meta={{ metric: 'revenue', delta: '-12%' }}>
  <RevenueChart />
</Askable>

<Askable meta={{ metric: 'revenue' }} scope="analytics">
  <RevenueChart />
</Askable>

<Askable meta="main navigation" as="nav">
  <NavLinks />
</Askable>

Props:

PropTypeDefaultDescription
metaRecord<string, unknown> | stringValue for data-askable attribute
scopestringOptional category written to data-askable-scope for scoped prompt/history queries
askeyof JSX.IntrinsicElements"div"HTML element to render
refRef<HTMLElement>Forwarded to the underlying element
...restAll other props forwarded to the element

useAskable(options?)

Hook that provides reactive access to a shared AskableContext for the requested events configuration. Observation starts after mount; additional consumers with the same events reuse the existing observer instead of re-observing the document. Differing events configurations get isolated shared contexts, each destroyed when its last consumer unmounts. Pass name to scope that shared lifecycle to a specific UI region (for example table vs chart).

ts
import { useAskable } from '@askable-ui/react';

const { focus, promptContext, ctx } = useAskable();

Options:

OptionTypeDescription
namestringOptional shared context name for region-scoped context reuse
viewportbooleanEnable viewport-aware context tracking for this hook's context
eventsAskableEvent[]Trigger events. Default: ['click', 'hover', 'focus']
ctxAskableContextProvide a custom context instead of the shared singleton

Returns:

ValueTypeDescription
focusAskableFocus | nullCurrent focused element data
promptContextstringNatural-language context string
ctxAskableContextFull context instance — select(), clear(), getHistory(), toHistoryContext(), etc.

Examples:

ts
// Restrict trigger events
const { focus } = useAskable({ events: ['click'] });

// Scoped context (multiple independent AI surfaces)
import { createAskableContext } from '@askable-ui/core';
const myCtx = createAskableContext();
myCtx.observe(panelEl);

const { focus } = useAskable({ ctx: myCtx });

Released under the MIT License.