What is the difference between viewModel() from the architecture components library and hiltViewModel()?
Asked Answered
C

0

6

As far as I can tell when using Jetpack Compose with Hilt there are two ways of creating/accessing a viewModel instance; viewModel() and hiltViewModel(). I can't understand which should be used as they seem to do the same thing. The documentation for viewModel() suggests that it automatically uses the View Model that Hilt constructs with @HiltViewModel. So what exactly is the difference between these two implementations and when should each be used?

Cincture answered 16/3, 2022 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.