Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created October 17, 2022 13:38
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/ab116f4e6afb253fe6b6766a5c59424c to your computer and use it in GitHub Desktop.
Save ch8n/ab116f4e6afb253fe6b6766a5c59424c to your computer and use it in GitHub Desktop.
increment by 1 using destructure
// 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 1
Button(
onClick = {
setCount(count + 1) //👈 update state
}
) {
Text(text = "Increment by 1")
} // button end
} // column end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment