What's the difference between this two approaches?...
# compose
s
What's the difference between this two approaches? And why first is preferable?
Copy code
@Composable
fun TestScreen(viewModel: TestViewModel = hiltViewModel()) {
    //content
}
Copy code
@Composable
fun TestScreen() {
    val viewModel: TestViewModel = hiltViewModel()
    //content
}
l
Using hilt, you can easily mock the view model in both cases. But the first one allows you to pass in a ViewModel without having to setup hilt at all, so you would usually go with that one
c
The top option has it's viewModel "dependency" injected (passed through constructor) so it's typically easier to swap it out for testing.