should viewmodels be annotated Stable?
# compose-android
z
should viewmodels be annotated Stable?
j
If ask me shouldnt be used in Compose at all, then no Stable annotation needed. Not used I mean never use in method arguments or inside Composable. Fine using outside with state hoisting etc :)
b
They are most likely not stable as well, so the answer would be no. We generally recommend you use them just at the top screen level composable and then after that just pass the state from the viewmodel down, not the viewmodel itself
j
I recommend using them only in Fragment and Activity and pass into composable. Not even root composable make sense imo :) also that will make your @Preview work for root composable as well. Create ui state from viewmodel and delegate to composable :)
f
I recommend using them only in Fragment and Activity and pass into composable
that's not feasible; you may not have fragments in a compose only app, and instantiating all your viewmodels in the activity, if you follow the single activity principle, means they will have all your viewmodels tied to the activity lifecycle instead of the more narrow nav graph lifecycle
s
Yes, so you gotta do what Ben said
top screen level composable
If you're using navigation this would be in your composable destination which defines its route