What is the difference between signal, computed and effect?
Model answer
signal holds a writable value. computed derives a value from other signals, is read-only, lazy and cached: it recalculates only when a dependency changes. effect runs side-effect code, such as logging or saving to local storage, when the signals it reads change.
Rule of thumb: use computed for values you can calculate from other state, and avoid using effects to set other signals, because that makes data flow harder to follow.
Tips
- Say what you would not do in an effect.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.