Skip to main content

useSignalsAlert

Loads one Signals episode or one raw alert by ID.

When to use it​

The default grain is an episode; episodes false selects a raw alert, and undefined ID disables loading.

Setup​

Call it from a client-side React component below OvokProvider so it uses the client configured at that provider boundary.

Hook arguments​

ArgumentTypeDetails
idstring or undefinedEpisode ID by default; undefined disables the request.
grainoptionalOmit for an episode; use the raw-alert grain for an individual alert.

The grain defaults to episodes. Set episodes: false when the workflow targets an individual raw alert.

TypeScript signature​

(id: string | undefined, grain: { episodes: false; }): OvokRequestState<SignalsRawAlert>
(id?: string, grain?: { episodes?: true; }): OvokRequestState<SignalsAlert>

Request state​

The hook returns an OvokRequestState whose data is a SignalsAlert by default or a SignalsRawAlert when { episodes: false } is selected. The remaining fields are data, loading, error, and reload.

FieldMeaning
dataThe selected episode or raw alert, or undefined before the request returns.
loadingWhether the alert lookup is in progress.
errorNormalized request error, if one occurred.
reloadRepeats the lookup for the current ID and grain.

Request behavior​

The hook loads when its required inputs are available and reloads when those inputs change. Use reload for an explicit refresh; render loading, error, and successful no-result states separately.

Example​

Handle the hook's loading and error states before rendering the result.

import { useSignalsAlert } from '@ovok/core';

export function EpisodeSummary({ id }: { id: string }) {
const { data, loading, error, reload } = useSignalsAlert(id);
if (loading) return <p>Loading alert…</p>;
if (error) return <p role="alert">{error.message}</p>;
return <section><pre>{JSON.stringify(data, null, 2)}</pre><button onClick={reload}>Refresh</button></section>;
}

// For an individual raw alert, call useSignalsAlert(id, { episodes: false }).

That overload returns SignalsRawAlert data:

import { useSignalsAlert } from '@ovok/core';

export function RawAlertSummary({ id }: { id: string }) {
const { data, loading, error } = useSignalsAlert(id, { episodes: false });
if (loading) return <p>Loading raw alert…</p>;
if (error) return <p role="alert">{error.message}</p>;
return <p>{data?.id ?? 'Raw alert not found'}</p>;
}