Skip to the page

Signals · core

signal, computed and effect

A signal holds a value you read by calling it. A computed is a lazy, cached value derived from signals. An effect runs a side effect when signals change.

The notes

What you must know

  • signal(value): read by calling count(), change with set or update.
  • Reading a signal inside a reactive context (a template, a computed, an effect) records a dependency.
  • computed(() => ...) is read-only, lazy and memoised. It runs when read after a dependency changed. Dependencies are tracked dynamically.
  • Signals compare with Object.is. update that returns the same array reference signals no change, so dependents are not notified.
  • Always return a new array or object from update: items.update(list => [...list, item]).
  • effect is for side effects such as logging, storage or calling non-Angular code. It is not for deriving values.
  • Signals are the main way to hold state in Angular (facts.md).

The red pen

Common traps: mistake → fix

  • Mistake: items().push(x) updates the screen

    Fix: the signal sees the same reference and sends no notification.

  • Mistake: An effect is the way to compute one value from another

    Fix: use computed.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is the difference between signal, computed and effect?
  2. Why does items.update(l => { l.push(x); return l }) not update count?
  3. When is an effect the right tool?
  4. Is computed lazy or eager?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview