How does this function keep track of clicks?

Viewed 64

On the "Thinking in Compose" page I don't get this code, how does $clicks keep track of number of clicks?

@Composable
fun ClickCounter(clicks: Int, onClick: () -> Unit) {
    Button(onClick = onClick) {
        Text("I've been clicked $clicks times")
    }
}

I'm learning Kotlin at the same time as Compose, so I get puzzled all the time.

1 Answers

It's omitted in that example but it should store the click-count in a MutableState<T> wrapped with remember

var clickCount by remember { mutableStateOf(0)}

ClickCounter(clicks = clickCount, onClick = {clickCount += it})
Related