on
Registers a handler for a store action. The handler runs after interceptors, alongside the built-in handler, and receives the action payload.
Usage
on<A extends keyof StoreActions>(
name: A,
handler: (data: StoreActions[A]) => void | boolean | Promise<boolean>,
config?: IEventConfig
): void;
| Parameter | Type | Description |
|---|---|---|
name | keyof StoreActions | Action id ("add-event", "update-event", "navigate-to", ...). |
handler | (data) => void | boolean | Promise<boolean> | Called with the action payload. Return value is ignored on on. |
config | IEventConfig | Optional bus config (tag, once); use tag to detach later. |
Use intercept instead of on when you need to block or modify an action before it runs.
Example
import { Calendar } from "@svar-ui/react-calendar";
import type { CalendarInstanceApi } from "@svar-ui/react-calendar";
function init(a: CalendarInstanceApi) {
api = a;
api.on("add-event", p => {
console.log("event added:", p.event);
});
}
<Calendar init={init} events={[]} date={new Date()} />
Related articles
intercept— block or confirm before the action runs.detach— remove a registered handler by tag.exec— programmatic equivalent of user actions.- Actions overview — payload shapes for each action.