Skip to content

watch

Watches an atom for changes and calls a function when the value changes.

import { watch, Atom } from '@reaxium/core';
function watch<T>(
store: Atom<T>,
fn: (value: T) => void
): () => void
NameTypeDescription
storeAtom<T>Atom to watch.
fn(value: T) => voidCallback on value change.
TypeDescription
() => voidFunction to unsubscribe.
const count = atom(0);
const unsubscribe = watch(count, (val) => console.log(val));