Skip to content

Guidance on sharing state between components #63

@pieterdd

Description

@pieterdd

It would be nice to have some guidance on best practices regarding state sharing between Relm4 components. These are the options I've considered so far:

  • Introduce global state using SharedState. This is relatively easily to implement but may make it harder to write isolated automated tests. The tab_game example uses this approach.
  • Pass down references to child components. I tried this at some point and got stuck trying to express the lifetime constraints.
  • Perhaps passing down RefCell/RefMut variables could work. Haven't tried this yet. It may sidestep lifetime issues but could introduce runtime panics if not managed properly.
  • Rely fully on message passing as opposed to shared state. This may be elaborate to maintain especially if there's a big hierarchy in your components.

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