@Composable
fun App() {
var count by remember { mutableStateOf(0) }
Column {
Button(onClick = { count++ }) {
Text("Counter: $count")
}
Child(count)
}
}
@Composable
fun Child(count: Int) {
fun onClick() {
println("Current counter: $count")
}
Column {
Button(onClick = { onClick() }) {
Text("Print with lambda")
}
Button(onClick = ::onClick) {
Text("Print with function reference")
}
}
}
After pressing the counter button at least once, the behavior of the two print buttons is different. The "Print with lambda" button prints the current counter while the "Print with function reference" button always prints the initial state 0. This feels really unintuitive. Is this intended and if yes, is there any documentation that describes this behavior?
As BenjyTec has pointed out, this behavior has been fixed in Compose 1.7.0.