Handling Side Effects & Working with the useEffect() HookEntry 7 of 7
Summary
| Concept | React | Angular |
|---|---|---|
| Run a side effect after render | useEffect | effect() / afterRenderEffect() |
| Run once on setup | useEffect(fn, []) | ngOnInit / constructor / afterNextRender |
| Dependencies | Listed by hand in an array | Tracked automatically from signal reads |
| Skip a dependency | Not allowed (restructure instead) | untracked() |
| Derived values | Compute in render / useMemo | computed() |
| Cleanup per run | Returned function | onCleanup() |
| Cleanup on destroy | Returned function ([] effect) | DestroyRef / ngOnDestroy |
| Stable function identity | useCallback / React Compiler | Class methods |
| Infinite loops possible? | Yes | Yes (writing a signal the effect reads) |
Both frameworks agree on the principle: effects are for synchronizing with the outside world, not for computing state. React makes you declare dependencies and manage function identity; Angular tracks signal dependencies and keeps methods stable, but a misused effect() can loop just the same.