Hi is there a better way to use `produceState` and `collectAsState`? ```val stateFlow by produceSt...
t
Hi is there a better way to use
produceState
and
collectAsState
?
Copy code
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
?
z
I’m not sure why you have the produceState at all, looks like you could just do:
Copy code
remember(viewModel) { viewModel.reduce(…) }.collectAsState(…)
collectAsState
just uses produceState under the hood though so you can always copy/paste the impl into your own code and modify it.
t
thanks very much for looking at this for me this
remember(viewModel) { viewModel.reduce(…) }.collectAsState(…)
works perfectly i ended up with
Copy code
val state by remember(viewModel) { viewModel.reduce(ActivitySearch) }.collectAsState(initial = InitialState)
the only thing i am unsure of is the
remeber(viewmodel)
part