store icon indicating copy to clipboard operation
store copied to clipboard

Date store not synced properly when using a selector

Open eEQK opened this issue 1 year ago • 1 comments

Describe the bug

given this store:

import { Store } from '@tanstack/react-store';

export const RootState = new Store({
    selectedDay: new Date(),
});

a is refreshed but b is not

export function DatePicker() {
  const a = useStore(RootState);
  const b = useStore(RootState, (s) => s.selectedDay);
  // ...
}

@thazlett16 said on discord:

I'm guessing this has to do with the shallow compare: https://github.com/TanStack/store/blob/main/packages/react-store/src/index.ts#L34

I know in Redux they generally recommend storing dates in a serializeable format like the string form (RFC 3339, ISO 8601 etc)

Steps to Reproduce the Bug or Issue

example here: https://stackblitz.com/edit/tanstack-store-thn7c7az?file=src%2Findex.tsx

Expected behavior

both a and b should refresh (unless dates are not supposed to be supported)

eEQK avatar Jan 19 '25 10:01 eEQK

I’m experiencing the same issue with dates.

illodev avatar Jan 31 '25 16:01 illodev

this also impacts tanstack/form when storing File instance. https://github.com/TanStack/form/issues/1539

therour avatar Jun 16 '25 19:06 therour