derivedStateOf

fun <T> derivedStateOf(calculation: () -> T): State<T>

Creates a State object whose State.value is the result of calculation. The result of calculation will be cached in such a way that calling State.value repeatedly will not cause calculation to be executed multiple times, but reading State.value will cause all State objects that got read during the calculation to be read in the current Snapshot, meaning that this will correctly subscribe to the derived state objects if the value is being read in an observed context such as a Composable function.

Samples

androidx.compose.runtime.samples.DerivedStateSample

Parameters

calculation

the calculation to create the value this state object represents.