compose-side-effects

Guides correct use of Jetpack Compose effect APIs for lifecycle-safe side work.

Updated May 21, 2025
One-click install
npx skills add https://github.com/albertmartorell1975/MeteoMartoCompose --skill compose-side-effects-albertmartorell1975
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: compose-side-effects
Source: https://github.com/albertmartorell1975/MeteoMartoCompose/tree/main/.agents/skills/compose-side-effects
Command: npx skills add https://github.com/albertmartorell1975/MeteoMartoCompose --skill compose-side-effects-albertmartorell1975

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Jetpack Compose composable bodies can be recomposed, skipped, or abandoned, so running side work directly in composition causes bugs like duplicate network calls, stale callbacks, leaked listeners, and missed Flow events. This Skill provides decision rules and code patterns for placing side work in the correct effect API. ## Core Features & Use Cases - Effect API selection: Decision table mapping each need to the right API: SideEffect, DisposableEffect, LaunchedEffect, rememberCoroutineScope, or snapshotFlow. - Key and stale-capture guidance: Rules for choosing effect keys, plus correct use of rememberUpdatedState and its eager-read trap inside remember blocks. - Flow collection and event patterns: Lifecycle-aware collection of event Flows, snapshotFlow usage, and rememberCoroutineScope for user-triggered suspending work. - Use Case: While reviewing a Compose screen, you notice LaunchedEffect(Unit) collecting a Flow keyed by a changing userId. The Skill identifies the missing key and shows the corrected LaunchedEffect(userId) pattern. ## Quick Start Review this Composable for side-effect mistakes and suggest the correct effect API and keys.

Frequently Asked Questions about compose-side-effects

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between LaunchedEffect and DisposableEffect in Compose?▼

Use LaunchedEffect for suspending, deferred, or keyed one-shot work such as collecting a Flow. Use DisposableEffect when you register a listener, callback, or resource that needs a matching onDispose cleanup.

When should I use rememberUpdatedState in Jetpack Compose?▼

Use rememberUpdatedState when a long-running effect must not restart but should invoke the latest callback, such as a timeout calling onTimeout. Do not use it to avoid proper keys, and never read its delegate eagerly inside a remember block.

Why does LaunchedEffect(Unit) cause bugs with changing parameters?▼

LaunchedEffect(Unit) never restarts, so it keeps capturing the first value of any changing parameter like a userId. Key the effect by the changing value, for example LaunchedEffect(userId), so the work restarts with fresh input.

How do I collect a Flow in a Compose screen correctly?▼

Collect event Flows such as snackbar or navigation events inside LaunchedEffect with a proper key. For UI render state, use collectAsStateWithLifecycle near the state holder and pass plain values into the UI composable.

Can I launch a coroutine from a button click in Compose?▼

Yes, use rememberCoroutineScope and call scope.launch inside the onClick callback for suspending work like showing a snackbar. Avoid setting an event flag in state just to trigger a LaunchedEffect.

Why does snapshotFlow do nothing without collect?▼

snapshotFlow only converts Compose snapshot reads into a Flow; the Flow is cold and inert until a terminal operator runs. You must call collect inside a LaunchedEffect for emissions to be observed.