atlassian / react-sweet-state

Shared state management solution for React

Home Page:https://atlassian.github.io/react-sweet-state/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dates don't work in selectors

mattcolman opened this issue · comments

Oh hi,

First time issue creator, long time fan of react-sweet-state.

I've noticed that if you return a Date from a selector then React components don't update.
After some digging I've found that when "update" runs it does a "shallowEqual" against previous and current values. Two different Dates are returning true with the custom shallowEqual function and therefore components never update. See screenshot for a test I wrote.

Image 2021-08-03 at 3 49 17 pm

Workaround for now is to wrap the date in an object like selector: state => ({ date: state.myDate })

Perhaps we can just add another "if statement" for instanceof Date to shallowEqual?

Thanks!!

@albertogasparin , i have tried to fixed the bug, can you please verify, here is the PR #147