collectAsRetainedState

fun <T> StateFlow<T>.collectAsRetainedState(context: CoroutineContext = EmptyCoroutineContext): State<T>(source)

Collects values from this StateFlow and represents its latest value via a retained State. The StateFlow.value is used as an initial value. Every time there would be new value posted into the StateFlow the returned State will be updated causing recomposition of every State.value usage.

Parameters

context

CoroutineContext to use for collecting.


fun <T : R, R> Flow<T>.collectAsRetainedState(initial: R, context: CoroutineContext = EmptyCoroutineContext): State<R>(source)

Collects values from this Flow and represents its latest value via retained State. Every time there would be new value posted into the Flow the returned State will be updated causing recomposition of every State.value usage.

Parameters

context

CoroutineContext to use for collecting.