Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created October 17, 2022 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ch8n/20bcfb439f418cc09ae29a0dd783a492 to your computer and use it in GitHub Desktop.
Save ch8n/20bcfb439f418cc09ae29a0dd783a492 to your computer and use it in GitHub Desktop.
increment by 2 using destrcuture
// Create a counter state
val(count, setCount) = remember {
mutableStateOf(0)
}
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.White),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
// display state on UI
Text(
text = "$count", //👈 display current value of state
fontSize = 32. sp,
)
// click button to increment count by 2
Button(
onClick = {
setCount(count + 1) //👈 update state 1st time
setCount(count + 1) //👈 update state 2nd time
}
) {
Text(text = "Increment by 2")
} // button end
} // column end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment