Jetpack Compose in Depth
Recomposition, state hoisting, remember and side effects, modifiers, theming and lazy layouts in Compose.
Intermediate · about 10 hours · difficulty 3/5
Learn first: Android Components, Lifecycle & Gradle
Compose redraws UI by recomposing composable functions when the state they read changes. Writing fast, correct Compose means working with that model, not against it.
State and recomposition
remember { mutableStateOf(...) }keeps state across recompositions;rememberSaveablealso survives configuration changes.- State hoisting: make composables stateless by passing
valueandonValueChange, keeping state in the caller or a ViewModel. This makes them reusable and previewable. - Composables should be side-effect free: they can run many times, in any order.
Side effects
LaunchedEffect(key)runs a coroutine when the key changes.DisposableEffectsets up and tears down listeners.rememberCoroutineScopelaunches work from click handlers.
Modifiers and layout
Modifier order matters: padding then background differs from the reverse. Use LazyColumn/LazyVerticalGrid with key for lists.
Tooling
@Preview for fast iteration, Layout Inspector to count recompositions.
Pitfalls
Reading rapidly changing state (scroll position) high in the tree recomposes everything; read it as late as possible or use derivedStateOf.
Good enough to move on: you built a stateless, previewable form component whose state lives in a ViewModel.
Key concepts
- Recomposition
- remember and rememberSaveable
- State hoisting
- Side-effect APIs
- Modifier ordering
- Lazy lists and grids
- Previews and Layout Inspector
- derivedStateOf and stability
Mini project
Build a habit tracker in Compose with a lazy list, a stateless habit row component, previews for each state, and a LaunchedEffect-driven reminder banner.
Check yourself
Why should a composable never perform a network request directly in its body?
Free resources
- Jetpack Compose (Android Developers)
- State and Jetpack Compose (Android Developers)
- Side-effects in Compose (Android Developers)