choosing-derivedstateof

Decides when Jetpack Compose derivedStateOf reduces recomposition and when it adds overhead.

1|Updated Jul 6, 2026
One-click install
npx skills add https://github.com/citytexi/team-yg-pesonal-agent --skill choosing-derivedstateof-citytexi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: choosing-derivedstateof
Source: https://github.com/citytexi/team-yg-pesonal-agent/tree/main/.claude/skills/choosing-derivedstateof
Command: npx skills add https://github.com/citytexi/team-yg-pesonal-agent --skill choosing-derivedstateof-citytexi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Jetpack Compose developers often wrap values in derivedStateOf without knowing whether it helps, causing either wasted snapshot subscriptions or missed recomposition optimizations. This Skill applies the "input frequency must exceed output frequency" rule to decide correctly and fixes the silent capture-by-initial-value bug. ## Core Features & Use Cases - Frequency-based decision rule: Compares input update rate against output change rate to determine whether derivedStateOf filters anything or is pure overhead. - Pitfall detection and fixes: Enforces the mandatory remember { derivedStateOf { } } wrapper, adds captured non-state variables as remember keys, and routes one-shot side effects to snapshotFlow inside LaunchedEffect. - Use Case: A scroll-driven FAB (firstVisibleItemIndex > 0) recomposes on every scrolled item; this Skill rewrites it with remember { derivedStateOf { } } so the composable only recomposes when the boolean flips, then verifies the drop in Layout Inspector. ## Quick Start Ask the AI to review your Compose code and decide whether a specific value should use derivedStateOf, remember with keys, a direct read, or snapshotFlow.

Frequently Asked Questions about choosing-derivedstateof

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

FAQPage Schema
When should I use derivedStateOf in Jetpack Compose?▼

Use derivedStateOf when the input state updates far more often than the derived output changes, such as converting firstVisibleItemIndex into a boolean. If input and output change at the same rate, it adds a snapshot subscription with no filtering benefit.

How do I fix derivedStateOf not updating in Compose?▼

A derivedStateOf that never updates usually captures a non-state variable by its initial value inside remember { }. Pass that variable as a remember key, for example remember(threshold) { derivedStateOf { ... } }, so a new derived state is created when it changes.

derivedStateOf vs snapshotFlow: which should I use?▼

Use derivedStateOf when a composable reads the derived value and should only recompose when the result changes. Use snapshotFlow inside LaunchedEffect for fire-and-forget side effects like analytics or snackbars, keeping the signal out of composition entirely.

Why is my recomposition count not dropping after adding derivedStateOf?▼

Recomposition counts stay high when the remember wrapper is missing, when input and output frequencies match, or when another state read or wrong-phase modifier invalidates the same scope. Verify with Layout Inspector or @TraceRecomposition before and after the change.

Should I wrap collectAsStateWithLifecycle results in derivedStateOf?▼

No. Wrapping a collected flow in derivedStateOf adds a subscription layer for nothing. Filter upstream on the flow itself using distinctUntilChanged() or map { } operators instead.