Guy Bieber
06/23/2020, 11:02 PMLeland Richardson [G]
06/23/2020, 11:08 PM@Composable fun Counter() {
var count = mutableStateOf(0)
Text("Count: ${count.value}")
Button(onClick={ count.value++ }) {
Text("Increment")
}
}
Leland Richardson [G]
06/23/2020, 11:09 PM@Composable fun Counter() {
val count = remember { mutableStateOf(0) }
Text("Count: ${count.value}")
Button(onClick={ count.value++ }) {
Text("Increment")
}
}
Leland Richardson [G]
06/23/2020, 11:10 PM@Composable fun Counter() {
val count = state { 0 }
Text("Count: ${count.value}")
Button(onClick={ count.value++ }) {
Text("Increment")
}
}
Leland Richardson [G]
06/23/2020, 11:10 PMgildor
06/24/2020, 1:42 AMstate { defaultValue }
even shorter and avoid such accidental introduction of state recreation
Or there is some important use case for mutableStateOf?Leland Richardson [G]
06/24/2020, 2:05 AMgildor
06/24/2020, 2:21 AMgildor
06/24/2020, 2:22 AMLeland Richardson [G]
06/24/2020, 3:01 AM