How StateFlow.collectAsState() works


val users = mainVM.users.collectAsState().value

Does .collectAsState() return a State-object, which becomes updated each time the users-collection changes?

Is then .value called automatically each time?

How do I think about the whole mechanism?

Corresponding code from the ViewModel:

private var _users = MutableStateFlow<List<User>>(emptyList())
val users = _users.asStateFlow()
0
Aug 8 at 6:14 AM
User Avatarcluster1
#advice#android#kotlin#android-jetpack-compose#kotlin-coroutines

No answer found for this question yet.