Skip to content

computed

Creates a derived, reactive value from other atoms.

import { computed, Atom } from '@reaxium/core';
function computed<T>(
fn: () => T,
deps: Atom<unknown>[]
): Atom<T>
NameTypeDescription
fn() => TFunction to compute the value.
depsAtom<unknown>[]Atoms to watch for changes.
TypeDescription
Atom<T>A computed atom instance.
const firstName = atom('John');
const lastName = atom('Doe');
const fullName = computed(
() => `${firstName.get()} ${lastName.get()}`,
[firstName, lastName]
);