🌈 Create new beautiful Compose Gradients with our new wesite ->
Composable Function

collectAsState

Collects values from this StateFlow and represents its latest value via State.

StateFlowSample

@Sampled
@Composable
fun StateFlowSample(stateFlow: StateFlow<String>) {
    val value: String by stateFlow.collectAsState()
    Text("Value is $value")
}

FlowWithInitialSample

@Sampled
@Composable
fun FlowWithInitialSample(flow: Flow<String>) {
    val value: String by flow.collectAsState("initial")
    Text("Value is $value")
}