Recomposition Explained
How Compose updates the UI.
Recomposition Explained is a free Android Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Recomposition?
Recomposition is Compose re-running your composable functions to update the UI when the state they read changes. It is how the screen stays in sync with your data.
Triggered by State Reads
Compose tracks which composables read which state. When a state value changes, only the composables that read it are scheduled to recompose.
Smart and Selective
Recomposition is selective: Compose tries to re-run as little as possible. A change to one piece of state will not redraw the whole screen — just the parts that depend on it.
Skipping
If a composable's inputs did not change, Compose can skip re-running it entirely. This keeps recomposition cheap even on complex screens.
Composables Run Often
Because recomposition can happen frequently and in any order, your composables must be safe to re-run. Calling one many times should produce the same UI for the same state.
Avoid Side Effects
Do not perform side effects (network calls, writing files, mutating shared variables) directly in a composable body. They might run on every recomposition. Use state and effect APIs instead.
// BAD: runs on every recomposition
@Composable
fun Bad() {
saveToDatabase()
Text("Hi")
}Order Independence
You cannot rely on composables running in a specific order or on a specific thread. Treat each call as independent. This freedom is what lets Compose optimize so aggressively.
Reading vs Not Reading
Only composables that read a state recompose when it changes. If a Text never reads count, changing count leaves it untouched.
@Composable
fun Demo() {
var count by remember { mutableStateOf(0) }
Text("Static") // never recomposes from count
Text("Count: $count") // recomposes when count changes
Button(onClick = { count++ }) { Text("+") }
}Recomposition Loops to Avoid
Writing to state during composition (not inside an event) can cause an endless recomposition loop. Update state only from callbacks like onClick, never directly in the body.
It Feels Automatic
From your point of view, recomposition is automatic. You declare UI as a function of state, change the state in callbacks, and Compose handles re-running the right composables.
Putting It Together
This counter demonstrates recomposition: tapping changes count, Compose re-runs the reading Text, and the new number appears.
@Composable
fun Counter() {
var count by remember { mutableStateOf(0) }
Button(onClick = { count++ }) {
Text(text = "Count: $count")
}
}Quick Check
When does Compose recompose a composable?
Recap
Recomposition essentials:
- State changes trigger re-running of composables that read that state.
- It is selective and can skip unchanged composables.
- Composables must be side-effect-free and safe to re-run in any order.
Frequently asked questions
Is the “Recomposition Explained” lesson free?
Yes — the full text of “Recomposition Explained” is free to read here on the web, and the Android Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Android Academy course, upgrade to CoddyKit PRO.
What will I learn in “Recomposition Explained”?
How Compose updates the UI. You practise Android Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Android Academy?
No prior experience is required. Android Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Recomposition Explained” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Android Academy lesson?
Yes. Every Android Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- State with remember and mutableStateOf
- Recomposition Explained
- State Hoisting
- rememberSaveable