Skip to content

CORRECT004 · Unmutated $state

Severity: info · Category: correctness

Flags a let x = $state(...) whose value is never written or escaped anywhere in the component — not reassigned, not mutated (x.a = …, x.push()), not bound (bind:value={x}), not passed to a function or component. Checked by static (CLI) analysis of the component script and template.

A $state that is never mutated pays for reactivity — deep proxying and dependency tracking — that it never uses. const is clearer and cheaper; $state.raw fits when you only ever reassign the value wholesale (never mutate its properties).

<script>
// Instead of: let title = $state('Dashboard');
const title = 'Dashboard';
// Reassigned wholesale but never deeply mutated? Use $state.raw:
let data = $state.raw(initial);
data = nextValue;
</script>