If I use hilt viewmodel in two composables on same...
# compose
j
If I use hilt viewmodel in two composables on same route ( same screen ) will it be same object or it will create two different objects? Sorry little bit newbie question 😞
z
Depends. Where are you creating the ViewModel? If you create it once then pass it to the two different Composables as parameter then obviously it will use the same ViewModel instance
j
Nah it works fine.
hiltViewModel
is already gonna return the same object from any composable within a single context, e.g. activity, fragment or a navigation route.
z
Depends how you scope it, you can easily create two different instances of a ViewModel even in the same screen
j
Nah I need same instance 😄
I know that I can with different keys right?