Skip to content

Scoped state tracking #479

Open
Open
@christianalfoni

Description

@christianalfoni

By extending the signature of useAppState we can scope the tracking of state.

const Item = ({ id }) => {
  const item = useAppState(state => state.items[id]) // Tracks ["items.$id"] and any other accessed state on item
}

This is different than doing:

const Item = ({ id }) => {
  const item = useAppState().items[id] // Tracks ["items", "items.$id"] and any other accessed state on item
}

The second example here also tracks the "items" themselves, meaning any added/removed items will cause this component to reconcile. We can currently solve this by passing the whole item down to the component, and do useAppState without using any actual state... this new solution seems more intuitive.

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