Hi, maybe kind of a noob question, but in android ...
# compose-desktop
c
Hi, maybe kind of a noob question, but in android we use viewmodel to hold data/states, here in compose for desktop what is the recommended thing to use ? if already asked or not related here, I'd like to atleast get the old answer or docs so I can get read it. Thanks in advance!
c
More than anything, the ViewModel is just a design pattern. The androidx
ViewModel
class and related libraries are all just implementation details to get around the error-prone lifecycle of Android apps. It's pretty easy to just create your own ViewModel class based around pure-Kotlin concepts like Flow, and have it live as a member of your Application or Window as appropriate. You can even just create and
remember
it directly within the composition where it is relevant, and let the composition itself dictate the ViewModel lifecycle, such as by handling any "inputs" to the ViewModel within
rememberCoroutineScope()
👍 4