Hi guys, how can we access/instantiate a viewModel...
# compose
b
Hi guys, how can we access/instantiate a viewModel inside a compose @Preview function
s
You shouldn't be working with viewmodels inside your previews. Read https://developer.android.com/jetpack/compose/state-hoisting#screen-ui-state particularly the section that says "Note: You shouldn't pass ViewModel instances down to other composables. For more information, see the Architecture state holders documentation." And that links to https://developer.android.com/topic/architecture/ui-layer/stateholders#business-logic
4
a
You want your composables to be testable so pull the viewmodel out so they dont have to depend on them
b
@Stylianos Gakis @alfredguimaz thanks for sharing, i think that’s the best approach