Created
October 17, 2022 13:38
-
-
Save ch8n/ab116f4e6afb253fe6b6766a5c59424c to your computer and use it in GitHub Desktop.
increment by 1 using destructure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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