Первая функция с производнымStateOf:
Код: Выделить всё
@Composable
private fun CounterWithDerivedState() {
val counterState = remember { mutableStateOf(0) }
val showFinallyState = remember {
derivedStateOf { counterState.value > 10 }
}
Button(
onClick = { counterState.value = counterState.value + 1 }
) {
Text(counterState.value.toString())
}
if (showFinallyState.value) Text("Finally!")
}
Код: Выделить всё
@Composable
private fun CounterWithRemberMutablState() {
val counterState = remember { mutableStateOf(0) }
val showFinallyState by remember(counterState) {
mutableStateOf(counterState.value > 10)
}
Button(
onClick = { counterState.value = counterState.value + 1 }
) {
Text(counterState.value.toString())
}
if (showFinallyState) Text("Finally!")
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... tablestate
Мобильная версия