derivedStateOf & snapshotFlow
Compute and observe derived state efficiently.
Computing Values from State
Sometimes a value depends on other state, like a button enabled only when a form is valid. Computing it well avoids wasteful recomposition.
Meet derivedStateOf
A derivedStateOf creates state from a calculation. It only notifies readers when the computed result actually changes, not on every input tweak.
val isValid by remember {
derivedStateOf { name.isNotBlank() && age > 0 }
}All lessons in this course
- LaunchedEffect for Coroutines
- rememberCoroutineScope for Events
- DisposableEffect & Cleanup
- derivedStateOf & snapshotFlow