udecode / zustand-x

Zustand store factory for a best-in-class developer experience.
https://zustand-x.udecode.dev
MIT License
356 stars 25 forks source link

Using `get` to retrieve store values doesn't trigger a component re-render #86

Closed vcardins closed 3 months ago

vcardins commented 3 months ago

Description

I might be using it wrongly, so excuse me in this case ... Using get to retrieve store values doesn't trigger a component re-render

Steps

  1. Create a component which listen to values
  2. Update store values in a different component/provider, etc
  3. Check whether the components which listen/consumes to the store value
  4. See error --> Notice it doesn't get updated

If I use get ... no re-renders

export const ParametersControl = memo(() => {
    const { set, get } = dataStore;

    const collection = get.collection?.();
    const collections = get.collections();
    const colorMap = get.colorMap();
    const time = get.time?.();

image

If I use use ... it re-renders

export const ParametersControl = memo(() => {
    const { set, use } = dataStore;

    const collection = use.collection?.();
    const collections = use.collections();
    const colorMap = use.colorMap();
    const time = use.time?.();

image

Expectation

Should get and use work the same way? What am I missing?