# Side Effects with `effect` and `afterRenderEffect`
In Angular, an **effect** is an operation that runs whenever one or more signal values it tracks change.
## When to use `effect`
Effects are intended for syncing signal state to imperative, non-signal APIs.
**Valid Use Cases:**
- Logging analytics.
- Syncing state to `localStorage` or `sessionStorage`.
- Performing custom rendering to a `<canvas>` or 3rd-party charting library.
**CRITICAL RULE: DO NOT use effects to propagate state.**
If you find yourself using `.set()` or `.update()` on a signal _inside_ an effect to keep two signals in sync, you are making a mistake. This causes `ExpressionChangedAfterItHasBeenChecked` errors and infinite loops. **Always use `computed()` or `linkedSignal()` for state derivation.**
## Basic Usage
Effects execute asynchronously during the change detection process. They always run at least once.
```ts
import { Component, signal, effect } from '@angular/core';
// Cleanup function runs before the next execution, or when destroyed
onCleanup(() => clearTimeout(timer));
});
}
}
```
## DOM Manipulation with `afterRenderEffect`
Standard `effect` runs _before_ Angular updates the DOM. If you need to manually inspect or modify the DOM based on a signal change (e.g., integrating a 3rd party UI library), use `afterRenderEffect`.
`afterRenderEffect` runs after Angular has finished rendering the DOM.