Skip to content
Commitwise
Menu

State hoisting

Moving state up to the caller, so a component receives its value as a parameter and reports changes through a callback.

Definition

A hoisted component is stateless: it gets the current value and a function to call when the user changes it. The caller owns the state. This keeps a single source of truth, makes components reusable and easy to preview and test. The rule of thumb is: values go down, events go up. It applies to Jetpack Compose and SwiftUI alike.

In practice

SearchField(query = query, onQueryChange = { query = it }) lets the screen own the text while the field just displays it.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.