Is there a suggested way to create a preview if I ...
# compose
e
Is there a suggested way to create a preview if I use a ViewModel? Create a preview with mocked data? I just saw the IDE said it didn't support for viewmodels, so I was curious what the best practice will be
d
Another alternative is to pass a data class with all of your state and callback functions in it.
👆 3
s
I'd extend this to say any reference to a stateful final class in a composable is something to add carefully as it makes your composable inherently stateful, which can make testing and preview harder.
g
I have my navigation pass the viewmodel through to a HoC composable which just collects data and function references and passess them to the main composable that represents the activity in rendering, and then the preview is just some data and empty functions passed through
e
@jim I was looking at the recommendations here: https://developer.android.com/jetpack/compose/state#viewmodel-state So we have a composable called Screen that is basically a MVVM binder, in which case I think it makes sense to pass a A-VM. The content composable on the other hand follows the logic you're talking about. i.e. passed as properties, and not a stateful object like an AVM with flows/LD. Actually, what I probably should've done in my case is add a preview for the Content composable instead, and then just pass mocked data for my preview. Thanks for the input! Thanks
👍 1