Hoist State with value & onValueChange
Pass state down, events up.
State Hoisting in One Line
State hoisting means moving state out of a Composable up to its caller. The component becomes stateless and the parent stays in charge.
The Core Pattern
Replace internal state with two parameters: a value to display and an onValueChange callback to report changes.
fun NameField(value: String, onValueChange: (String) -> Unit) {
TextField(value = value, onValueChange = onValueChange)
}All lessons in this course
- Stateful vs Stateless Composables
- Hoist State with value & onValueChange
- Single Source of Truth
- Compose State Slots & Content Lambdas