Save state in mutableStateOf directly in composabl...
# compose
a
Save state in mutableStateOf directly in composable, or save state using mutableStateFlow in viewmodel and consume it as collectAsState() in composable, which one is the better?
m
It depends. In general, I like to pull as much logic out of the view and into the view model, so having state in the view model makes sense. But for things that only the view cares about, I'll leave it in the composable. I have also played with using mutable state in the view model instead of a flow if the state is only being observed by the view.
1