Skip to content

Instantly share code, notes, and snippets.

@phatnhse
Created July 29, 2023 00:11
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 phatnhse/ffa167de5f073936c0bbae619f9506c0 to your computer and use it in GitHub Desktop.
Save phatnhse/ffa167de5f073936c0bbae619f9506c0 to your computer and use it in GitHub Desktop.
recompose
@Composable
fun Sample() {
var button1 by remember { mutableStateOf("button 1") }
var button2 by remember { mutableStateOf("button 2") }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
// Recomposes when `button1` changes, but not when button2 changes
Button(onClick = { button1 += "1" }) { Text(text = button1) }
Spacer(modifier = Modifier.height(8.dp))
// Recomposes when `button2` changes, but not when button1 changes
Button(onClick = { button2 += "2" }) { Text(text = button2) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment