Composable Function

collectAsState

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

FlowWithInitialSample

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

StateFlowSample

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