Mobile development

Stage 2 · Lesson 6 of 10

State in Compose: remember and hoisting

Jetpack Compose UI

A holds state with remember { mutableStateOf(...) }. When the value changes, Compose recomposes (re-runs) whatever reads it. remember survives , but not a rotation or the system killing the app in the background. keeps simple values across both.

is the key pattern. A reusable composable does not own its state. Instead it takes the value and an onValueChange callback, like the built-in TextField, so the caller decides where the state lives.

That makes components reusable, testable and previewable. The next stage moves screen state into a .

Common trapwriting a plain var inside a composable, which resets on every recomposition and never triggers an update.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with

Practise

  • Use a free challenge's mobile design image as the spec for a native screen

Keep handy

  • Spacing, type scale, colour and component specs your screens should follow

Mark this stage as not done?