0Pricing
Sveltejs Academy · Lesson

derived() for Computed Stores

Derive a new store whose value is computed from one or more other stores.

derived() for Computed Stores is a free Sveltejs Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Sveltejs Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What derived Does

derived creates a new store whose value is computed from one or more source stores.

Import It

From svelte/store.

import { derived } from "svelte/store";

Single Source

Derive from one store: pass it and a function returning the derived value.

export const doubled = derived(count, ($count) => $count * 2);

Multiple Sources

Pass an array of stores; the callback receives an array of their values.

export const total = derived([price, qty], ([$p, $q]) => $p * $q);

Async Derived

Pass a second argument set and call it asynchronously to derive from an async source.

derived(userId, ($id, set) => {
  fetchUser($id).then(set);
});

Initial Value

Async deriveds accept a third argument as the initial value before set is called.

Auto Cleanup

Like other stores, derived auto-cleans subscriptions to its sources.

Chaining

Derived stores can themselves serve as sources for other deriveds.

Memoization

The derived value updates only when source values change. Equivalent to memoized selectors.

Use in Components

Consume with the $ shorthand like any other store.

<p>Total: {$total}</p>

When to Use

Use derived for computed shared state; for component-local computed values, prefer $:.

Quick Check

What does derived return?

Recap

derived builds computed read-only stores from one or many sources. Supports sync and async derivations.

Frequently asked questions

Is the “derived() for Computed Stores” lesson free?

Yes — the full text of “derived() for Computed Stores” is free to read here on the web, and the Sveltejs Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Sveltejs Academy course, upgrade to CoddyKit PRO.

What will I learn in “derived() for Computed Stores”?

Derive a new store whose value is computed from one or more other stores. You practise Sveltejs Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Sveltejs Academy?

No prior experience is required. Sveltejs Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “derived() for Computed Stores” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Sveltejs Academy lesson?

Yes. Every Sveltejs Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. derived() for Computed Stores
  2. Custom Store Pattern with subscribe/set/update
  3. Readable from Writable
  4. Store Contracts and Interoperability
← Back to Sveltejs Academy