watch
Watches an atom for changes and calls a function when the value changes.
Signature
Section titled “Signature”import { watch, Atom } from '@reaxium/core';
function watch<T>( store: Atom<T>, fn: (value: T) => void): () => void
Parameters
Section titled “Parameters”Name | Type | Description |
---|---|---|
store | Atom<T> | Atom to watch. |
fn | (value: T) => void | Callback on value change. |
Returns
Section titled “Returns”Type | Description |
---|---|
() => void | Function to unsubscribe. |
Example
Section titled “Example”const count = atom(0);const unsubscribe = watch(count, (val) => console.log(val));