Skip to content
RED SAGSkills
easy5 pts · first answer countsandroidjetpack-composestate

Counter jumps back to zero

The count sometimes jumps back to 0, for example when the parent screen recomposes. Why?

@Composable
fun Counter() {
    var count by mutableStateOf(0)
    Button(onClick = { count++ }) {
        Text("Count: $count")
    }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions