Skip to content
GitHubXDiscord

@triggery/jotai

Read a Jotai atom from a Triggery condition. Pull-only: store.get(atom) runs only when a trigger fires, the host component is never subscribed to atom updates.

npm bundle

pnpm add @triggery/core @triggery/react @triggery/jotai jotai

Peer deps: react >= 18.0.0, jotai ^2.

ExportPurpose
useJotaiCondition(trigger, name, store, atom, selector?)Register an atom-backed condition. Supports an optional projection selector.
import { atom, createStore } from 'jotai';
import { createTrigger } from '@triggery/core';
import { useJotaiCondition } from '@triggery/jotai';

type Settings = { sound: boolean; notifications: boolean };

const settingsAtom = atom<Settings>({ sound: true, notifications: true });
const store = createStore();

const messageTrigger = createTrigger<{
  events: { 'new-message': { text: string } };
  conditions: { settings: Settings };
  actions: { showToast: { body: string } };
}>({
  id: 'message-received',
  events: ['new-message'],
  required: ['settings'],
  handler({ event, conditions, actions }) {
    if (!conditions.settings.notifications) return;
    actions.showToast?.({ body: event.payload.text });
  },
});

function SettingsBridge() {
  useJotaiCondition(messageTrigger, 'settings', store, settingsAtom);
  return null;
}

With a projection selector:

useJotaiCondition(messageTrigger, 'settings', store, profileAtom, (p) => p.settings);

Pull-only: store.get(atom) runs only when a trigger fires, not on every atom update. The host component is never re-rendered by atom changes — that’s useAtomValue’s job and lives in the components that actually render the value.

useJotaiCondition<V, S, K>(
  trigger: Trigger<S>,
  name: K,
  store: { get<V>(atom: Atom<V>): V },
  atom: Atom<V>,
  selector?: (value: V) => ConditionMap<S>[K],
): void