compose-side-effects

Explain Compose side-effects lifecycle and place work in SideEffect, LaunchedEffect, and DisposableEffect.

1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/leogallego/ansible-jane --skill compose-side-effects-leogallego
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-side-effects
Source: https://github.com/leogallego/ansible-jane/tree/main/skills/compose-side-effects
Command: npx skills add https://github.com/leogallego/ansible-jane --skill compose-side-effects-leogallego

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Composable functions recompose frequently, but side-work that touches external state must be anchored to a lifecycle via SideEffect, DisposableEffect, LaunchedEffect, and related APIs. Without proper lifecycles, effects can leak, restart unexpectedly, or capture stale data.

Core Features & Use Cases

  • Guidance on choosing the right effect API for lifecycle-bound work, one-shot suspending tasks, and listener registrations.
  • Best practices for avoiding stale captures, proper cleanup, and lifecycle-safe emissions from flows.
  • Real-world scenarios include collecting a Flow in response to UI state, registering a listener on screen enter, or running a startup task.

Quick Start

Create a composable that uses LaunchedEffect(key) to collect a Flow and update UI whenever new items arrive.

Frequently Asked Questions about compose-side-effects

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

FAQPage Schema
How do I collect a Flow safely in Jetpack Compose without causing recomposition leaks?

To collect a Flow safely in Jetpack Compose, use LaunchedEffect with a key to anchor collection to the composable lifecycle, ensuring emissions update UI state without leaking effects or capturing stale data during recomposition.

When should I use DisposableEffect vs LaunchedEffect for registering listeners in Compose?

Use DisposableEffect when registering listeners in Compose to ensure proper cleanup on lifecycle exit, whereas LaunchedEffect is for one-shot suspending work, preventing listener leaks and unexpected restarts during recomposition.

What is the best way to perform one-shot suspending work in response to a Compose UI event?

The best way to perform one-shot suspending work in Compose is using LaunchedEffect keyed to the UI event, which scopes the coroutine to the composable's lifecycle and cancels stale tasks on recomposition.

Why does my Compose side-effect capture stale data during recomposition?

Compose side-effects capture stale data when work touches external state without proper lifecycle anchoring via SideEffect, LaunchedEffect, or DisposableEffect, causing effects to restart unexpectedly or hold outdated references.

Do I need SideEffect to align work with recomposition in Android Compose?

Yes, you need SideEffect to align work with recomposition in Android Compose when you must publish state changes to non-Compose objects safely after every successful recomposition without leaking side-work.