What does remember do in Jetpack Compose?
remember stores a value in the composition so it survives recompositions. It keeps state across UI updates.
What is the purpose of mutableStateOf in Jetpack Compose?
mutableStateOf creates a state holder that can be observed. When its value changes, Compose recomposes the UI that reads it.
How do remember and mutableStateOf work together?
You use remember to keep the mutableStateOf value across recompositions. This way, the state is saved and UI updates when the value changes.
What happens if you use mutableStateOf without remember inside a composable?
The state will reset on every recomposition because mutableStateOf creates a new state each time. You lose the saved value.
Give a simple example of using remember and mutableStateOf to hold a counter value.
@Composable
fun Counter() {
val count = remember { mutableStateOf(0) }
Button(onClick = { count.value++ }) {
Text("Count: ${count.value}")
}
}What does remember do in Jetpack Compose?
remember keeps a value alive during recompositions so the UI can keep state.
What is the role of mutableStateOf?
mutableStateOf holds a value that Compose watches to update UI when it changes.
What happens if you forget to use remember with mutableStateOf inside a composable?
Without remember, the state is recreated each time, losing previous value.
Which of these is the correct way to declare a state variable for a counter?
Use remember with mutableStateOf to keep state across recompositions.
What triggers recomposition when using mutableStateOf?
Changing the value inside mutableStateOf triggers Compose to recompose affected UI.
Explain how remember and mutableStateOf work together to manage state in Jetpack Compose.
Describe what happens if you use mutableStateOf without remember inside a composable function.