How do you avoid common problems with effects?

Angular signals and change detection · Experienced

Model answer

Do not use effects to copy one signal into another; use computed or linkedSignal. Avoid setting signals inside effects unless you really need to, because it can create confusing update chains and loops. Keep effects for side effects: logging, analytics, syncing with local storage or a non-Angular library, and DOM work.

Clean up with the onCleanup callback if the effect starts timers or listeners, and read signals you do not want to track with untracked().

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions