Skip to content
GitHubXDiscord

useInspect

Stable · since 0.1.0

Returns the most recent TriggerInspectSnapshot for a single trigger, or undefined if the trigger has not run yet. Useful for inline debug overlays, “last run at” timestamps, or quick “did it actually fire” assertions in dev panels.

useInspect does not subscribe to new runs — it reads the latest snapshot every render and returns it as-is. Pair it with useInspectHistory for a live feed of recent runs.

import { useInspect } from '@triggery/react';
function useInspect<S extends TriggerSchema>(
  trigger: Trigger<S>,
): TriggerInspectSnapshot | undefined;
ParamTypeDescription
triggerTrigger<S>The trigger returned by createTrigger.

The latest TriggerInspectSnapshot or undefined if the trigger has not run yet (or if the runtime has the inspector disabled).

Snapshot fieldTypeDescription
triggerIdstringSame as trigger.id.
runIdstringUnique per-run id.
eventNamestringThe event that matched.
status'fired' | 'skipped' | 'errored' | 'aborted'Run outcome.
reason?stringSet when status is 'skipped', 'errored', or 'aborted'.
durationMsnumberHandler wall time.
executedActionsreadonly string[]Names of actions invoked during the run.
snapshotKeysreadonly string[]Condition keys read by the handler.
import { useInspect } from '@triggery/react';
import { messageTrigger } from './triggers/message.trigger';

function DebugBadge() {
  const snap = useInspect(messageTrigger);
  if (!snap) return null;
  return (
    <span style={{ color: snap.status === 'fired' ? 'green' : 'orange' }}>
      {snap.status} ({snap.durationMs.toFixed(1)}ms)
    </span>
  );
}

Quick “did it fire” assertion in dev tools

Section titled “Quick “did it fire” assertion in dev tools”
import { useInspect } from '@triggery/react';
import { fetchUserTrigger } from './triggers/fetch-user.trigger';

function FetchUserDebug() {
  const snap = useInspect(fetchUserTrigger);
  return (
    <pre>
      {snap
        ? JSON.stringify(
            { id: snap.runId, status: snap.status, actions: snap.executedActions },
            null,
            2,
          )
        : '(no runs yet)'}
    </pre>
  );
}
import { useInspect } from '@triggery/react';
import { syncTrigger } from './triggers/sync.trigger';

function LastSync() {
  const snap = useInspect(syncTrigger);
  if (!snap || snap.status !== 'fired') return <span>never</span>;
  return <span>last sync: {snap.runId}</span>;
}