Ellen Spertus
08/17/2022, 2:50 AMIn Compose, you call the composable function again with new data. Doing so causes the function to be recomposed--the widgets emitted by the function are redrawn, if necessary, with new data. The Compose framework can intelligently recompose only the components that changed.
For example, consider this composable function which displays a button:
```@Composable
fun ClickCounter(clicks: Int, onClick: () -> Unit) {
Button(onClick = onClick) {
Text("I've been clicked $clicks times")
}
}```
Every time the button is clicked, the caller updates the value ofI don't understand why the last sentence is true. We don't see the.clicks
onClick
function. Are we supposed to infer that it is () -> clicks++
and that clicks
is bound to the parameter?Ben Trengrove [G]
08/17/2022, 2:53 AMEllen Spertus
08/17/2022, 3:01 AMClickCounter
to be called again. Are you saying that the onClick
method calls ClickCounter
?onClick
method called ClickCounter()
, I'd understand.Ben Trengrove [G]
08/17/2022, 3:03 AM@Composable
fun MyScreen() {
var clickCount by remember { mutableStateOf(0) }
ClickCounter(clickCount, onClick = { clickCount ++ })
}
Ellen Spertus
08/17/2022, 3:05 AMClickCounter
might be called?Ben Trengrove [G]
08/17/2022, 3:06 AMEllen Spertus
08/17/2022, 3:07 AM