@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.
Install
Section titled “Install”pnpm add @triggery/core @triggery/react @triggery/jotai jotai npm install @triggery/core @triggery/react @triggery/jotai jotai yarn add @triggery/core @triggery/react @triggery/jotai jotai bun add @triggery/core @triggery/react @triggery/jotai jotai Peer deps: react >= 18.0.0, jotai ^2.
What’s inside
Section titled “What’s inside”| Export | Purpose |
|---|---|
useJotaiCondition(trigger, name, store, atom, selector?) | Register an atom-backed condition. Supports an optional projection selector. |
Quick example
Section titled “Quick example”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);How it works
Section titled “How it works”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],
): voidRelated packages
Section titled “Related packages” @triggery/core Exposes Trigger.
@triggery/react useJotaiCondition is a React hook.
@triggery/zustand Alternative adapter for Zustand stores.
@triggery/redux Alternative adapter for Redux stores.
@triggery/reatom Reatom atom adapter — similar pull-only model.
@triggery/signals Adapter for @preact/signals-core and alien-signals.