Created
October 16, 2023 16:14
-
-
Save alexaleluia12/3035d05279f8ccc97be2110217c24d71 to your computer and use it in GitHub Desktop.
Composable Kotlin
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
// source - https://stefma.medium.com/jetpack-compose-remember-mutablestateof-derivedstateof-and-remembersaveable-explained-270dbaa61b8 | |
@Composable | |
private fun CounterWithDerivedState() { | |
// salvar stado em caso a activity seja recaregada - rememberSaveable | |
val counterState = remember { mutableStateOf(0) } | |
val showHurrayState = remember { | |
derivedStateOf { counterState.value > 10 } | |
} | |
Button( | |
onClick = { counterState.value = counterState.value + 1 } | |
) { | |
Text(counterState.value.toString()) | |
} | |
if (showHurrayState.value) Text("Hurray!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment