compose-side-effectslisted
Install: claude install-skill pablitoarango/android-skills
# Compose Side Effects
Sources of truth: [Side-effects in Compose](https://developer.android.com/develop/ui/compose/side-effects), [State](https://developer.android.com/develop/ui/compose/state), [Performance best practices](https://developer.android.com/develop/ui/compose/performance/bestpractices).
Composables must be **free of side effects**: they only describe UI from their inputs and may run at any time, in any order, as often as every frame. Any work that changes something outside the composition goes through an effect API.
## 1. Pick the effect
| Need | API |
|---|---|
| Run suspending work tied to the composable, restarting when inputs change | `LaunchedEffect(keys) { }` |
| Launch a coroutine from an event handler (click, gesture) | `rememberCoroutineScope()` |
| Register something that must be cleaned up (listener, observer, receiver) | `DisposableEffect(keys) { ...; onDispose { } }` |
| Publish Compose state to non-Compose objects after every successful recomposition | `SideEffect { }` |
| Turn a non-Compose source (Flow, callback, repository call) into `State` | `produceState(initial, keys) { }` |
| Recompose only when a computed value actually changes | `remember { derivedStateOf { } }` |
| Use Flow operators on Compose state | `snapshotFlow { }` inside `LaunchedEffect` |
| Start and stop work with the Activity lifecycle | `LifecycleStartEffect` / `LifecycleResumeEffect` (see `compose-ui`) |
| Observe a ViewModel `StateFlow` | `collectAsStateWithLifecycle()`