0Pricing
Jetpack Compose Academy · Lesson

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

  1. Stateful vs Stateless Composables
  2. Hoist State with value & onValueChange
  3. Single Source of Truth
  4. Compose State Slots & Content Lambdas
← Back to Jetpack Compose Academy