Data & State — Overview
React gives you a rich but fragmented menu: useState, useReducer, useContext, useRef, Redux, Zustand, react-query, SWR — each solving a different slice of the state problem. Svelte has a layered model that covers the same ground with fewer moving parts:
$state— component-local reactive state (replacesuseState)$derived— computed values that update automatically (replacesuseMemo)$effect— side effects that re-run on dependency change (replacesuseEffect)- Svelte stores (
writable,readable,derived) — shared state across components .svelte.tsmodules — module-level reactive state, imported like any JS module{#await}— declarative async/loading/error state in markup
This module walks through each layer. Start here for a map, then dive into the dedicated lessons.
Component-local state: useState → $state
Section titled “Component-local state: useState → $state”function Counter() { const [count, setCount] = React.useState(0); return ( <button onClick={() => setCount(c => c + 1)}> Count: {count} </button> );}<script> let count = $state(0);</script>
<button onclick={() => count++}> Count: {count}</button>The key difference: $state variables are plain mutable variables. No setter, no functional update — just assign. Svelte’s compiler tracks reads and writes at the call site.