Skip to main content
There are two ways to react to widget activity: lifecycle hooks (declarative, through config) and the event emitter (imperative, through widget.on).

Hooks

Pass callbacks through config.hooks:
interface EventHooks {
  onNudgeShown?: (nudge: NudgeData) => void;
  onStateChange?: (from: WidgetState, to: WidgetState) => void;
  onError?: (error: Error) => void;
  onQuickAction?: (action: QuickActionType) => void;
}

const config: MindConfig = {
  authCookieKey: 'session',
  hooks: {
    onStateChange: (from, to) => console.log(`${from}${to}`),
    onNudgeShown: (nudge) => console.log('nudge:', nudge.type),
    onQuickAction: (action) => console.log('action:', action),
  },
};

Event emitter

The widget extends an event emitter. Subscribe with widget.on and clean up with widget.off.
EventPayload
stateChange(from: WidgetState, to: WidgetState)
contextChange(event: ContextChangeEvent)
nudgeShown(nudge: NudgeData)
quickAction(action: QuickActionType)
authFailed() — fires after any SDK request returns 401. The widget hides itself automatically; subscribe to this event to drive the host’s re-auth flow.
mounted(container: HTMLElement)
shown()
hidden()
destroyed(container: HTMLElement | null)
useEffect(() => {
  const onChange = (from: WidgetState, to: WidgetState) =>
    console.log('state:', from, '→', to);

  widget.on('stateChange', onChange);
  return () => widget.off('stateChange', onChange);
}, [widget]);