Skip to main content
InterviewHubPRO
Section Overview
Q6

Question 6 of 50

Part 1: Architecture, Jetpack Compose & Core Components (1 - 10)

12%
Android & Jetpack Compose (50 Qs)•Part 1: Architecture, Jetpack Compose & Core Components (1 - 10)

What is State Hoisting in Jetpack Compose?

senior LevelMost AskedCode ExampleComponentsClosures & ScopeDocker & Containers

In Simple Words: State hoisting is a programming pattern of moving state up to a caller component to make a composable stateless:

  • Replaces internal state with two parameters:
    1. value: T: The current value to display.
    2. onValueChange: (T) -> Unit: An event callback lambda requesting the value to change.
  • Benefits: Makes composables reusable, decoupled, and easy to unit test.
kotlin
// Stateless hoisted composable:
@Composable
fun NameInput(name: String, onNameChange: (String) -> Unit) {
    TextField(value = name, onValueChange = onValueChange, label = { Text("Name") })
}