Implementing ViewModel classes and understanding the state in Compose
In Android, a ViewModel
is a class responsible for consciously managing the UI-related data life cycle. There is also a lot of debate in the community about whether developers should use ViewModel
in Compose or not. However, Manuel Vivo, a senior Android developer relations engineer at Google, says:
“I’d include them if their benefits apply to your app. No need to use them if you handle all configuration changes yourself and don’t use Navigation Compose. Otherwise, use ViewModels not to reinvent the wheel.”
“On the other hand, the debate as to why one should not use ViewModels is based on the argument that in pure Compose, since Compose handles configuration changes, having your Composable functions reference the ViewModel is unnecessary.”
You can also refer to this tweet by Jim Sproch: https://twitter.com/JimSproch/status/1397169679647444993.
Note
You can...