Stage 2 · Lesson 6 of 10
State in Compose: remember and hoisting
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
- CourseFreeAndroid Basics with Compose
Google · Beginner
Units 2 and 3: Compose layouts, state, scrollable lists and Material theming