Skip to content

Passing ViewModel instance to child components #1

@NeverwinterMoon

Description

@NeverwinterMoon

I am not sure this adheres to the official recommendations, thus not making it very clean. As I understand, view model instances shouldn't be passed down to children components. Say, you have view model at GroupScreen - this is where it should be - but it shouldn't be passed down to children views, such as AddGroupDialog:

https://developer.android.com/topic/architecture/ui-layer/stateholders#viewmodel-as

Warning: Don't pass ViewModel instances down to other composable functions. Doing so couples the composable function with the ViewModel type, making it less reusable and harder to test and preview.

AddGroupDialog should not be aware of the model. It can get states and some callbacks passed down from the page component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions