Search code examples
kotlinandroid-jetpack-composeside-effects

Is it okey to call collect within a Composable


I took a look at this tutorial and within it the author explains that making network calls in a composable is a bad habit. But what about getting the results in a StateFlow in a composable is that to a bad habit? Or is that okey? So the question is that when you call collect on a MutableStateFlow is it okey to do that directly in the compose method and not in the a side effect block?


Solution

  • Not only it is not a bad habit, it is the only way to actually use the result in composable. I wouldn't expose MutableStateFlow but rather only StateFlow, but the rest is just fine