Viewmodel instantiated in Compose with hiltviewmodel() called multiple times

Viewed 674

I am trying to open a compose detail page with Viewmodel added using hiltviewmodel() The viewmodel has a paging data state and an API call result state which is needed to show the updated data along with the list.But when I navigate to the detail page, the viewmodel methods are called multiple times, even the init {} block also. Anyone facing same issue like this, or got any solution?

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun DashboardScreen(
    navController: NavController,
    dashboardViewModel: DashboardViewModel = hiltViewModel(),
    Name: String = ""
) {
    val lazyArticleList = dashboardViewModel.articlePages.collectAsLazyPagingItems()
    val dashState = dashboardViewModel.dashboardState.value
}
0 Answers
Related