Skip to main content

derivedStateOf

Function derivedStateOf 

Source
pub fn derivedStateOf<T: 'static + Clone + PartialEq>(
    compute: impl Fn() -> T + 'static,
) -> State<T>
Expand description

A state computed from other states, as in Kotlin.

compute runs in a scope of its own: the states it reads subscribe that scope, not the composable reading the result, and a change to them runs compute again without recomposing anyone. The readers recompose only when the result differs from the last one. A composable that reads derivedStateOf(|| index_under(offset.get())) as an offset animates recomposes once per new index rather than once per frame.