Koskamo

Reactive state with the $state rune

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

The $state rune creates reactive state: the UI reacts when the value changes. There is no special API for interacting with state — a value like count is just a number, updated like any other variable. When $state wraps an array or a simple object, the result is a deeply reactive state proxy, so property reads and writes, including mutations through methods like array.push(...), trigger granular updates to whatever depends on that specific property. State is proxified recursively until Svelte meets something other than an array or simple object, such as a class instance. Two caveats matter in practice: destructuring a reactive value breaks reactivity, because destructured references are evaluated at the point of destructuring, and class instances are not proxied — instead use $state in class fields or as the first assignment inside the constructor. For objects you do not want deeply reactive, $state.raw declares state that cannot be mutated, only reassigned, and $state.snapshot takes a static snapshot of a proxy; reactive Set, Map, Date, and URL implementations are importable from svelte/reactivity. Scope: Svelte 5. Reviewed October 4, 2026.

Source and provenance

Original source
svelte.dev
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.