Compose State & Hoisting
UI › Compose Core
Drills observable state, remember, hoisting, unidirectional data flow, and state ownership in Compose.
Interviewers use this topic to check whether you understand how Compose actually re-renders UI and where state should live. Expect to explain why a TextField won't update without state, distinguish remember from rememberSaveable, refactor a stateful composable into a stateless hoisted one, and justify keeping state in a composable versus a plain holder versus a ViewModel. It separates people who memorized APIs from those who understand the snapshot/recomposition model and unidirectional data flow.
What this covers
- How mutableStateOf produces observable State that schedules recomposition when reads change
- remember (survives recomposition) vs rememberSaveable (survives config change / process death) and what each can store
- Refactoring stateful into stateless composables via hoisting with value + onValueChange
- Unidirectional data flow: state flows down, events flow up; single source of truth
- derivedStateOf to compute state that changes less frequently than its inputs and avoid wasted recomposition
- Choosing the owner: composable vs plain state holder vs ViewModel, and the three hoisting rules
Study this topic
- Compose State & Hoisting explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- Compose State & Hoisting interview questions and answers