Derived
Now that you can mutate state with .on(), derived properties let you compute
values from that state automatically — recalculating only when their dependencies
change. Use .derived() to keep complex logic out of your templates and make
components easier to reason about.
The callback receives the component context, just like .on(). The result is
available in .render() via derived.name.value. Unlike state, you never
write to a derived property directly — it always reflects the latest computed result.
.derived() also accepts an async function, making it suitable for data fetching.
The result exposes value, loading, and error — so you get built-in async
state without reaching for SWR or TanStack Query.
Similar concepts
- React:
useMemo - Vue:
computed() - Svelte:
$derived()