BeCuriouzBeCuriouz

Learn something new every day

📱 Mobile Programming
🔄

In Jetpack Compose, your UI isn't updated — it's re-run

💡 Compose UIs aren't mutated after creation — reading observable state makes the framework re-run (recompose) exactly the functions that depend on that state.

In the old Android View system, you built a screen once and then reached back into it to mutate it: textView.setText(...), button.setEnabled(false). Jetpack Compose throws that model out. In Compose you write composable functions that describe what the UI should look like for a given state. You never edit widgets after the fact — instead, when the underlying data changes, Compose simply calls your functions again. This re-execution is called recomposition.

The trick that makes this efficient is state. When you read a value created with mutableStateOf (usually via remember { mutableStateOf(...) }), Compose quietly records that this composable depends on that value. Change the value and Compose re-runs only the functions that read it — not the whole screen. So a counter's Text recomposes when the count changes, while an untouched header nearby does not.

This is why Compose is called declarative: you declare Text("Count: $count") once, and the framework keeps the pixels in sync with count for you. There is no setText. The mental shift for beginners is to stop thinking "how do I change the UI?" and start thinking "what state describes the UI, and how does that state change?"

🔄 In Jetpack Compose, your UI isn't updated — it's re-run — BeCuriouz