Is there ever a reason to collectAsState() anymore...
# compose-android
b
Is there ever a reason to collectAsState() anymore when collecting state that's in a viewModel from a Screen/Composable? Or should we always collectAsStateWithLifecycle() in this circumstance? This video makes it seem like most of the time you'd want to use collectAsStateWithLifecycle()

https://www.youtube.com/watch?v=0G_1XCRlpYM

. Though collectAsState isn't deprecated nor shows a warning that you'd most likely want to use collectAsStateWithLifecycle() instead?
👍 1
l
It's possible it's not deprecated because of multiplatform. This method is Android-specific.
b
@Landry Norris That makes sense! It could be cool if it was annotated with something that would basically say, "Consider using collectAsStateWithLifecycle() on Android with this package" if it was the case that you should almost always use that method instead. Though I'm still not clear on if that's the case, or in an Android project there's still reason to collectAsState()
j
Yeah I did my own kotlin extension using collectAsState if not Android and lifecycle variant on Android with expect/actual. Would be cool if androidx did this automatic.
Also quite bad documented its nice using whileSubscribed combined to tell parent or sibling observers stop upstream.