Signals vs React State: Fine-Grained Reactivity
On this page
Learning Objective
Explain how signal-based reactivity tracks dependencies automatically and updates only the affected DOM, compare it with React's re-render and diff model, use signals, computed values and effects correctly, and understand the TC39 signals proposal and the trade-offs between the two approaches.
Concept Explanation
Frameworks must answer one question after every state change: what needs to update? React answers coarsely and then refines: when state changes, it re-runs the component function and its children and diffs the new element tree against the old one to find what changed in the DOM. That model is simple to reason about, since every render is a fresh snapshot, but it does work proportional to the size of the re-rendered subtree, which is why memoization exists (Day 89).
Signals answer precisely from the start. A signal is a reactive container for a value. Reading it inside a reactive context, such as a computed value, an effect or a template binding, automatically registers that context as a subscriber. Writing it notifies exactly those subscribers. A computed, or derived, signal calculates a value from other signals, caches it and recalculates only when one of its dependencies changes, and only when it is read. An effect runs side effects when the signals it read change. The result is a dependency graph built at run time, and an update walks only the affected part of it, all the way down to individual text nodes and attributes.
Most modern frameworks have converged on this model. SolidJS made signals central: its components run once to set up the graph, and afterwards only fine-grained bindings update; there is no virtual DOM and no re-rendering of components. Preact Signals, Vue's ref and computed, Svelte 5's runes, Angular's signal and computed, and Qwik's signals are all variations on the idea. React is the notable exception, keeping its snapshot and re-render model, now with the React Compiler memoizing automatically to reduce re-render costs.
Signals change some habits. Because component functions in Solid run once, destructuring props or reading a signal outside a reactive context captures a value once and loses reactivity, a common beginner bug. Derived values should be computed signals rather than effects that copy one signal into another, the same advice as Day 54's warning against effects for derived data. Updates are synchronous and glitch-free in well-designed libraries: a computed value never observes a half-updated state. Batching groups several writes so subscribers run once.
The TC39 Signals proposal aims to standardize a core signal primitive in JavaScript itself, with Signal.State, Signal.Computed and a low-level watcher for effects, developed with input from the authors of Angular, Vue, Solid, Preact, Svelte, Ember and MobX. The goal is interoperability: reactive state created by one library could drive another's UI. It is an early-stage proposal, so frameworks continue to ship their own implementations for now. The trade-off between the models is real: signals give surgical updates and predictable performance at scale, while React's snapshot model gives simple mental semantics where any value can be used anywhere during render. Both are good choices; understanding both makes it easier to move between ecosystems.
| Concept | Signals model | React model |
|---|---|---|
| State | signal(value) | useState |
| Derived value | computed(() => ...), cached | Computed during render, useMemo if slow |
| Side effects | effect tracks what it reads | useEffect with a dependency array |
| Dependency tracking | Automatic at run time | Manual dependency arrays |
| What re-runs on change | Only subscribed computations and bindings | Component and its children |
| Virtual DOM | Usually none | Yes, diffed each render |
| Typical pitfall | Reading outside a reactive scope | Stale closures, extra re-renders |
Worked Example: A Cart in Preact Signals and the Same Logic in Solid
The signals version updates only the text nodes that display totals. Changing a quantity does not re-render the list component.
// Preact Signals: works in Preact and, with an adapter, in React
import { signal, computed, effect, batch } from '@preact/signals';
const items = signal([
{ sku: 'A1', name: 'Mug', qty: 1, cents: 1200 },
{ sku: 'B2', name: 'Tea', qty: 2, cents: 450 },
]);
const count = computed(() => items.value.reduce((n, i) => n + i.qty, 0)); // cached
const totalCents = computed(() => items.value.reduce((n, i) => n + i.qty * i.cents, 0));
const freeShipping = computed(() => totalCents.value >= 5000); // depends on a computed
effect(() => { document.title = `Cart (${count.value})`; }); // re-runs when count changes
function setQty(sku: string, qty: number) {
batch(() => { // one notification for several writes
items.value = items.value.map((i) => (i.sku === sku ? { ...i, qty } : i));
});
}
const totalText = computed(() => formatCents(totalCents.value));
const shippingText = computed(() => (freeShipping.value ? '(free shipping)' : ''));
export function CartSummary() {
// Passing signals themselves into JSX binds the text nodes directly: the component never re-renders.
// Reading count.value here instead would subscribe the whole component and re-render it on change.
return <p>{count} items, total {totalText} {shippingText}</p>;
}// SolidJS: components run once; only bindings update
import { createSignal, createMemo, For } from 'solid-js';
function Cart() {
const [items, setItems] = createSignal(initialItems);
const total = createMemo(() => items().reduce((n, i) => n + i.qty * i.cents, 0));
console.log('Cart setup runs once');
return (
<>
<For each={items()}>{(item) => <Row item={item} onQty={(q) => setItems((xs) => xs.map((x) => (x.sku === item.sku ? { ...x, qty: q } : x)))} />}</For>
<p>Total: {formatCents(total())}</p> {/* only this text node updates */}
</>
);
}
// Pitfall: const { item } = props in Solid reads once and loses reactivity; use props.item.Add a console.log to each component body in both versions and change a quantity: the Solid setup log appears once on mount and never again, while in an equivalent React component the log appears on every change.
Real-World Examples
- Angular introduced signals in version 16 in 2023 and has progressively moved its change detection toward them, including zoneless change detection, so that updates no longer depend on Zone.js patching browser APIs to detect when anything might have changed.
- The TC39 Signals proposal was published in 2024 by contributors including Rob Eisenberg and Daniel Ehrenberg with input from maintainers of Angular, Vue, Solid, Preact, Svelte and other frameworks, and it reached stage 1 as a standardization effort for a shared reactive primitive.
Review Questions & Answers
When a signal is read inside a reactive context, such as a computed value, an effect or a template binding, the library records that context as a subscriber. When the signal is written, it notifies exactly those subscribers, so dependencies are tracked automatically at run time.
A computed signal derives a value from other signals, caches it and recalculates lazily when its dependencies change and it is read. An effect performs side effects, such as updating the document title, whenever the signals it read change. Derived data should use computed values, not effects that write other signals.
Solid component functions run only once. Destructuring reads the prop values at that moment and stores plain values, so later changes are not seen. Accessing props.item inside JSX or a reactive scope keeps the read reactive.
Signals update only the affected computations and DOM nodes, giving precise, predictable performance without manual memoization, but require keeping reads inside reactive scopes. React's re-render model treats each render as a simple snapshot where any value can be used freely, at the cost of re-running components and needing memoization in hot paths.