Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created October 18, 2022 04:35
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/17ede4f49e0c6090f532be7bde8888d2 to your computer and use it in GitHub Desktop.
Save ch8n/17ede4f49e0c6090f532be7bde8888d2 to your computer and use it in GitHub Desktop.
Equivalent code
@Composable
fun Foo() {
val countState = remember { mutableStateOf(0) }
Button(onClick = {
val count = countState.value //👈 count is 0
val setCount = { lastestCount: Int ->
countState.value = lastestCount
}
setCount(count+1) //👈 0 + 1
setCount(count+1) //👈 0 + 1
}) {
Text(text = "Increment by 2")
}// button end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment