intercept
Registers a handler that runs before regular handlers for a given action. Returning false (or a promise resolving to false) cancels the action.
Usage
intercept<A extends keyof StoreActions>(
action: A,
handler: (data: StoreActions[A]) => void | boolean | Promise<boolean>,
config?: IEventConfig
): void;
interface IEventConfig {
tag?: string | number | symbol;
}
| Parameter | Type | Description |
|---|---|---|
action | keyof StoreActions | Action name (e.g. "add-event", "delete-event", "navigate-to"). |
handler | (data) => void | boolean | Promise<boolean> | Receives the payload. Return false to cancel; anything else lets it proceed. |
config | IEventConfig | Optional. Pass tag to identify the interceptor for later detach. |
Example
import { useState } from "react";
import { Calendar } from "@svar-ui/react-calendar";
import type { CalendarInstanceApi } from "@svar-ui/react-calendar";
const [api, setApi] = useState<CalendarInstanceApi>();
const init = (a: CalendarInstanceApi) => {
setApi(a);
a.intercept("delete-event", ({ id }) => {
return confirm(`Delete event ${id}?`);
});
};
<Calendar events={[]} init={init} />
Related articles
on— observe actions instead of cancelling them.detach— remove a registered interceptor by tag.exec— actions that flow through the interceptor chain.- Actions overview — payload shape per action.