Skip to content
GitHubXDiscord

@triggery/reatom

Read a Reatom atom or computed from a Triggery condition. Pull-only: the atom is called only when a trigger fires, no subscriber is registered against it.

npm bundle

pnpm add @triggery/core @triggery/react @triggery/reatom @reatom/core

Peer deps: react >= 18.0.0, @reatom/core ^1000 || ^1001.

ExportPurpose
useReatomCondition(trigger, name, atom, selector?)Register a Reatom-backed condition. Works with any callable Reatom primitive — atoms, computeds, derived values.
import { atom } from '@reatom/core';
import { createTrigger } from '@triggery/core';
import { useReatomCondition } from '@triggery/reatom';

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

const $settings = atom<Settings>({ sound: true, notifications: true });

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() {
  useReatomCondition(messageTrigger, 'settings', $settings);
  return null;
}

With a projection selector:

useReatomCondition(messageTrigger, 'settings', $profile, (p) => p.settings);

Pull-only: the atom is called (atom()) only when a trigger fires. No subscriber is registered, so the host component never re-renders on atom updates. Use Reatom’s own React bindings (reatomComponent, useAtom) in components that need to render the value.

useReatomCondition<V, S, K>(
  trigger: Trigger<S>,
  name: K,
  atom: () => V,
  selector?: (value: V) => ConditionMap<S>[K],
): void