Complete the code to declare a Compose state variable that triggers recomposition when changed.
var count by remember { mutableStateOf([1]) }The initial value of the state variable count should be 0 to track a number. This triggers recomposition when count changes.
Complete the code to update the state variable and trigger recomposition on button click.
Button(onClick = { count [1] 1 }) { Text("Increment") }Using += increases the count by 1, triggering recomposition to update the UI.
Fix the error in the code to properly observe state changes and trigger recomposition.
val count = mutableStateOf([1])
Text(text = count.value.toString())The initial value must be an integer 0, not a string, to match the expected type and allow recomposition.
Fill both blanks to create a composable function that remembers a state and updates it on button click.
var text by remember { mutableStateOf([1]) }
Button(onClick = { text = [2] }) { Text("Change Text") }The state text starts as "Hello" and changes to "World" when the button is clicked, causing recomposition.
Fill all three blanks to create a stateful composable that toggles a boolean and shows text accordingly.
var isOn by remember { mutableStateOf([1]) }
Button(onClick = { isOn = ![2] }) {
Text(if (isOn) [3] else "Off")
}The state isOn starts as false. Clicking toggles it by negating isOn. The text shows "On" when true, else "Off".