JetBrains/intellij-community / .claude/skills/compose-ui
compose-ui
VerifiedWrite or audit Compose Desktop UI state, effects, and boundaries.
audit/references/effects/effect-selection-guide.md
View on GitHub# Effect Selection Guide
## Quick reference
| Situation | Use | Don't use |
|-----------|-----|-----------|
| Fire-and-forget async work | `LaunchedEffect(key)` | `SideEffect` |
| Run code on every successful composition | `SideEffect` | `LaunchedEffect` |
| Setup/teardown a resource | `DisposableEffect(key)` | `LaunchedEffect` + manual cleanup |
| Callback inside a long-lived effect | `rememberUpdatedState` | Restarting effect on callback change |
| Derive state without cascading recompositions | `derivedStateOf` | Direct transformation |
| Convert Snapshot state to Flow | `snapshotFlow` | Manual polling |
## LaunchedEffect
```kotlin
LaunchedEffect(userId) {
val data = repository.fetch(userId)
uiState.value = UiState.Success(data)
}
```
- Runs in a coroutine scoped to the composition.
- Cancels and restarts when `key` changes.
- `key` can be `Unit` for "run once" semantics.
- **Do not** write to state in a tight loop without suspension — this causes CPU starvation.
## SideEffect
```kotlin
SideEffect {
analytics.trackScreenView("Settings")
}
```
- Runs after every successful composition (not on every recomposition attempt).
- Use `SideEffect` to publish Compose state to non-Compose systems such as analytics, logging, and imperative view
updates.
- **Do not** launch coroutines here — use `LaunchedEffect`.
## DisposableEffect
```kotlin
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event -> /* ... */ }
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
```
- `onDispose` runs when the composable leaves composition or the key changes.
- **Always** provide a non-empty `onDispose`. Missing cleanup is a memory leak.
## rememberUpdatedState
```kotlin
val currentOnTimeout by rememberUpdatedState(onTimeout)
LaunchedEffect(Unit) {
delay(5000)
currentOnTimeout() // calls the latest callback, not the one at launch
}
```
- Wraps a value so it can be read without triggering recomposition or effect restart.
- Use when an effect must observe a prop that changes frequently.
## derivedStateOf
```kotlin
val isScrolled by remember {
derivedStateOf { scrollState.value > 0 }
}
```
- Creates a new state that derives from upstream state.
- Downstream composables only recompose when the derived value changes, not when upstream
changes.
- Use when the derivation filters or collapses changes.
## snapshotFlow
```kotlin
LaunchedEffect(Unit) {
snapshotFlow { searchQuery.value }
.debounce(300)
.flatMapLatest { query -> search(query) }
.collect { results -> state.value = results }
}
```
- Reads Snapshot state and emits values as a Flow.
- Use for complex reactive pipelines (debounce, switchMap, etc.).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |