hi there! I’m wondering how to manage state in com...
# compose-desktop
l
hi there! I’m wondering how to manage state in compose desktop. Are you using viewmodels? We use viewmodel in android because of it’s lifecyclle aware but here there is no change orientation and that stuff. Do you create your own viewmodel? Or are you using MVI, MVP?
t
Also in Android there are problems when using viewmodels in compose components read this: https://jetc.dev/slack/2021-04-17-preview-viewmodel.html
But at the end you need something like that. In compose for desktop i do not have really a simple solution yet. I think you could use singletons. Or use any system of singletons. At the end it depends on the lifecycle of your viewmodels. If it is engough when they are live as long as the composable than you can just create State classes instead of viewmodels. And use remember { YourStateClass() } to remember them.
m
The navigation framework I use has a ViewModel implementation, called ScreenModel that works really well https://github.com/adrielcafe/voyager