on
Registers a handler that runs after the store's default handler for a given action. Use it to react to confirmed state changes - logging, syncing to a backend, or updating derived UI.
Usage
on(
action: keyof StoreActions,
handler: (data: StoreActions[typeof action]) => void | boolean | Promise<boolean>,
config?: { tag?: string | number | symbol }
): void;
action- the action name to listen for (e.g."update-card","move-card")handler- callback that receives the action payload after the store has processed itconfig.tag- optional identifier for later removal withdetach(tag)
Example
api.on("update-card", ({ id, card }) => {
console.log(`Card ${id} updated`, card);
});
// Tag a handler for later removal
api.on(
"move-card",
({ id, column }) => {
saveToBackend(id, column);
},
{ tag: "sync" }
);
// Remove it later
api.detach("sync");