Course contentsShow
← JavaScript
Lesson 2117 of 2,72344. Reactive PatternsFree lesson

What Are Signals?

Introduction to signals as a reactive primitive that holds state and automatically notifies dependents when the value changes.

What Are Signals?

You'll learn what signals are as a reactive primitive and why they're becoming a cornerstone of modern JavaScript state management.

The Core Idea

A signal is a reactive container that holds a single value and automatically notifies any dependent code when that value changes. Unlike the Observer pattern you just learned—where you manually register observers with a subject—signals handle dependency tracking automatically. When you read a signal's value inside a computation or effect, that computation becomes a dependent. When the signal updates, all dependents re-run without you writing subscription code.

Think of a signal like a spreadsheet cell: when you change cell A1, any formula referencing A1 recalculates instantly. You don't tell each formula "hey, A1 changed"—the spreadsheet tracks dependencies for you.

Why Signals Matter

Traditional state management (like in React's older class components) required manual wiring: you'd update state, then explicitly tell the UI which parts to re-render. Signals flip this: you declare what depends on what, and the framework handles the rest.

The Observer pattern you just studied requires explicit subscribe() and unsubscribe() calls. Signals eliminate that boilerplate by tracking reads during execution. When a function accesses a signal, that function is automatically registered as a dependent.

The Reactive Primitive

Signals are called a "primitive" because they're the building block for other reactive patterns. Effects (which run side effects when dependencies change) and computed values (derived state) both build on signals. This creates a fine-grained reactivity system where only the minimal necessary code re-runs.

Key Takeaway: Signals are self-contained reactive values that automatically track and notify dependents when changed, eliminating manual subscription management from the Observer pattern.