Tower Guidev2
10/03/2022, 10:04 AMproduceState
and collectAsState
?
val stateFlow by produceState<Flow<Stateable>>(initialValue = flowOf(InitialState), true) {
value = viewModel.reduce(ActivitySearch)
}
val state by stateFlow.collectAsState(initial = InitialState)
in my composable?
is there an approach where i can combine the produceState
with the collectAsState
?Zach Klippenstein (he/him) [MOD]
10/04/2022, 10:50 AMremember(viewModel) { viewModel.reduce(…) }.collectAsState(…)
Zach Klippenstein (he/him) [MOD]
10/04/2022, 11:11 AMcollectAsState
just uses produceState under the hood though so you can always copy/paste the impl into your own code and modify it.Tower Guidev2
10/04/2022, 3:40 PMremember(viewModel) { viewModel.reduce(…) }.collectAsState(…)
works perfectly
i ended up with
val state by remember(viewModel) { viewModel.reduce(ActivitySearch) }.collectAsState(initial = InitialState)
the only thing i am unsure of is the remeber(viewmodel)
part