Hey :wave: Folks I'm seeing both `collectAsState`...
# compose
p
Hey 👋 Folks I'm seeing both
collectAsState
and
collectAsStateWithLifecycle
is taking in a param
context
Should i be passing
viewLifecycleOwner.lifecycleScope.coroutineContext,
Copy code
val state by viewModel.orderDetailsLiveData.asFlow().collectAsState(
    initial = null,
    context = viewLifecycleOwner.lifecycleScope.coroutineContext,
)
To collect the state properly when i'm using fragments + compose ? When should someone be using
context
param ?
i
It has a default because you usually don't need to change it. It is rare that it matters what context you collect on
p
🙇 Thanks for the reply Can you think of a case where i might want to collect it in a different context ? I can see this code after going down a bit. Was thinking when will someone be passing a different context
m
Since you started with a LiveData, would it make more since to use the LiveData state binding instead of converting to flow and then collecting the flow. I guess it might be an extra library, but then you might be able to remove the library that converts from LiveData to Flows. https://developer.android.com/jetpack/compose/state#use-other-types-of-state-in-jetpack-compose
p
Yeah. that can be changed.