Hosting our states in Compose
summary
Explains concrete patterns: move state to a top-level host so composables stay stateless, pass values plus onValueChange lambdas, and encapsulate complex UI state in a single stakeholder object (ViewModel or data class). Shows use of remember{ } and rememberSaveable for recomposition and process restore, and demonstrates lifecycle‑safe collection of StateFlow/SharedFlow with repeatOnLifecycle / flowWithLifecycle so flows don’t leak. Includes code sketches and a working alpha library approach for safe flow collection.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 1:58State and recomposition basics
- 8:48Composition lifecycle explained
- 15:40Remember and state management
- 21:34State hosting in Compose
- 27:50Stakeholders and UI logic
- 31:27Flow collection safety
- 35:30Lifecycle-aware flow collection
- 41:57Best practices summary
related talks
11mInvest in Real State: A workshop for State in Compose
34mArchitectures in the Compose World
42mJetpack Compose: Art of the State
27mBuilding State Holders in Compose with Molecule
34mBeyond the UI: Compose as a Foundation for Multiplatform Apps
19mUsing Jetpack libraries in Compose
38mBuilding StateFlows in Android with Jetpack Compose
36mWhat State Hides in Compose
