compose-side-effects

Guide Jetpack Compose side effects with LaunchedEffect, DisposableEffect, and SideEffect.

13|Updated Jun 24, 2021
One-click install
npx skills add https://github.com/costular/Minitask --skill compose-side-effects-costular
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-side-effects
Source: https://github.com/costular/Minitask/tree/main/.agents/skills/compose-side-effects
Command: npx skills add https://github.com/costular/Minitask --skill compose-side-effects-costular

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill helps you handle side effects in Jetpack Compose effectively, avoiding common pitfalls such as stale captures, redundant restarts, and lifecycle mismanagement.

Core Features & Use Cases

  • Effective Side Effects: Provides guidelines on choosing the right effect (LaunchedEffect, DisposableEffect, SideEffect) and effect keys to ensure code clarity and performance.
  • Preventing Stale Captures: Offers solutions to manage effect keys and remember updated states to avoid common pitfalls in managing UI side effects.
  • Flow Collection and User Events: Details best practices for using flows in LaunchedEffect and handling user events efficiently.
  • Registration and Cleanup: Explains how to properly set up and clean up lifecycle observers and disposables for a clean, bug-free experience.

Quick Start

Utilize this skill to analyze the use of effects in your Jetpack Compose project, focusing on ensuring the appropriate usage of side effects, proper handling of keys, and preventing common errors related to side effect lifecycles.

Frequently Asked Questions about compose-side-effects

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

FAQPage Schema
How do I handle side effects in Jetpack Compose without lifecycle issues?

To handle side effects in Jetpack Compose safely, you must use lifecycle-aware effect APIs like LaunchedEffect and DisposableEffect with proper key management to prevent stale captures and redundant restarts.

What is the difference between LaunchedEffect, DisposableEffect, and SideEffect in Jetpack Compose?

LaunchedEffect runs suspend functions tied to keys, DisposableEffect handles setup and cleanup for lifecycle observers, and SideEffect publishes recomposition state to non-Compose code on every successful composition.

Why does my Jetpack Compose LaunchedEffect capture stale state values?

Your Jetpack Compose LaunchedEffect captures stale state when effect keys are not updated or managed properly. Using rememberUpdatedState allows your effect to reference the latest value without restarting its coroutine.

How do I collect flows in Jetpack Compose without causing redundant restarts?

To collect flows in Jetpack Compose without redundant restarts, use LaunchedEffect with stable keys and rememberUpdatedState. This ensures continuous flow collection while safely updating the UI with the latest emitted values.

When should I use DisposableEffect for registration and cleanup in Jetpack Compose?

Use DisposableEffect for registration and cleanup in Jetpack Compose when you need to attach lifecycle observers or manage external resources, ensuring the disposable block removes them cleanly to avoid memory leaks.