when i use kotlinViewModel() to get view model i a...
# compose
h
when i use kotlinViewModel() to get view model i am getting new instance of viewmodel, shouldn't it return it the same instance. The issue is I have 2 view models running now.
Copy code
@Composable
 fun RootUINavigation(
     navController: NavHostController,
     paddingValues: PaddingValues,
     transfersViewModel: TransfersViewModel = koinViewModel(),
     mainNavController: NavController,
     allStocksViewModel: AllStocksViewModel = koinViewModel(),
 ) {
val allStocksState by allStocksViewModel.allStocksState.collectAsState()
val transfersScreenUIState by transfersViewModel.uiState.collectAsState()
Copy code
NavHost(
         navController = navController,
         startDestination = Stocks
     ) {
Copy code
composable<Stocks> {
             AllStocksScreen(
                 paddingValues = paddingValues,
                 state = allStocksState,
                 mainNavController = mainNavController
             )
         }
Copy code
composable<Transfers>{
             TransfersScreen(
                 paddingValues = paddingValues,
                 uiState = transfersScreenUIState,
                 onAction = {
                     transfersViewModel.onAction(it)
                 }
             )
         }
Copy code
composable<Portfolio>{
             PortfolioScreen()
         }
}
}
screenshot_20250202_224002_tradingapp.jpg
a
Are you saying you expect
TransfersViewModel
and
allStocksViewModel
to be the same instance? They aren’t the same type.