Is there any reason to use ViewModel on web target...
# compose-web
t
Is there any reason to use ViewModel on web target (WASM/JS)?
s
Pretty much the same as for other targets, separation of concerns. To strip business logic from composables to make them stateless and easier to reuse. testing, etc And you can share them in common code
☝🏻 1
a
@Tanish Azad there is no real benefit no. as @S. it's only for architecture reasons
t
Hmm ok, thanks guys
c
technically. ViewModel on android is debateable. Jim Sproch (the guy that started compose at google) says its not needed. i personally (being an android dev) definitely cling onto it. and use it on ios. typically not on desktop though
s
technically you don't need it in android xml either. If you mean this comment from Jim Sproch, he only advises against platform specific code like the Android VM. But now we even have a common viewmodel. Or this says to not pass a viewmodel into your composable functions. Obviously you should use proper state hoisting instead and have viewmodels at a screen level. This has nothing to do with the architectural decision to decouple ui from business logic.
Do you just not share all code with desktop or how do you handle it?