Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Created March 28, 2022 21:07
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 halilozercan/d56b2e03545c58c5ed66cc276b5155b0 to your computer and use it in GitHub Desktop.
Save halilozercan/d56b2e03545c58c5ed66cc276b5155b0 to your computer and use it in GitHub Desktop.
@Composable
fun Parent() {
Column {
var length by remember { mutableStateOf(1) }
val stringy by remember { derivedStateOf { { "a".repeat(length) } } }
ThingCounter(stringy)
Button(onClick = { length++ }) {
Text(text = "Change stringy")
}
}
}
@SuppressLint("UnrememberedMutableState")
@Composable
fun ThingCounter(stringy: () -> String) {
var count by mutableStateOf(0)
Button(onClick = { count++ }) {
Text("You've had $count ${stringy()}.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment