Avoiding common coroutines mistakes in Compose
summary
Compose code repeatedly launches coroutines when those launches live directly inside composable bodies, causing a snackbar to pop endlessly if recomposition happens every second; the fix is to use LaunchedEffect with keys instead of ad hoc rememberCoroutineScope launches. Creating a flow inside composition restarts it on every recomposition so the pizza loader animation resets unless the flow is remembered across recompositions. UI observing a StateFlow sees no updates until it uses collectAsStateWithLifecycle (or collectAsState) so live prices actually update.
AI-written summary · about
chapters (7)
- 0:00Intro
- 2:31Composable functions can...
- 5:03Creating coroutines in the composition
- 7:23A positive example
- 8:59Creating Flows in the composition
- 11:39Using StateFlow values
- 13:56Summary
related talks
45mMastering Recomposition: Optimizing State Changes for Efficient UI
37mPerformance in Compose:Lessons learned from Lazy layouts
40mCompose Without Flow: Unidirectional State with Snapshots and Coroutines
55mOptimising UI in Jetpack Compose
28mCompose at Scale: Stop Unnecessary Recomposition
38mMastering Jetpack Compose Side-effects
42mJetpack Compose: Art of the State
45mCoroutines, Flow & Android- The Good Parts
