Shouldn't `val vm: MyViewModel = viewModel()` alw...
# compose
d
Shouldn't
val vm: MyViewModel = viewModel()
always retrieve the same ViewModel object in different composables but in the same activity?
h
I think there is already an abstraction responsible for this behaviour called ViewModelStoreOwner. Compose also follows this principle with AmbientViewModelStoreOwner. That's why the closest parent which provides ViewModelStoreOwner is responsible for which ViewModel to return. Navigation Compose also takes advantage of this behaviour to make sure that viewmodels are tied to navigation destinations, rather than activity or fragments.
❤️ 1
d
Navigation Compose also takes advantage of this behaviour to make sure that viewmodels are tied to navigation destinations, rather than activity or fragments.
Ah, that's what tricked me! Thanks a lot, Halil!