Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSelector does not update when selector returns a map #1286

Closed
iamawebgeek opened this issue May 16, 2019 · 2 comments
Closed

useSelector does not update when selector returns a map #1286

iamawebgeek opened this issue May 16, 2019 · 2 comments

Comments

@iamawebgeek
Copy link

Do you want to request a feature or report a bug?
bug

What is the current behavior?
useSelector method uses shallowEqual util to force update when value is changed and it does not work when I compare 2 es6 maps.

const map = new Map()
const newMap = new Map(map)
newMap.set('key1', 'value1')
console.log(map === newMap) // false
console.log(shallowEqual(map, newMap)) // true

Example
https://codesandbox.io/s/charming-jennings-mbfu5?fontsize=14

What is the expected behavior?
shallowEqual util with 2 different maps should return false

Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?
React: v16.8.6
Redux: v7.1.0-alpha.4

@timdorr
Copy link
Member

timdorr commented May 16, 2019

We are using the exact same code as React uses for shallowEqual, which is the same behavior as connect. In general, you shouldn't be storing non-serializable objects in your store, nor using them for selecting out data. There are tradeoffs and this is one of them.

@timdorr timdorr closed this as completed May 16, 2019
@iamawebgeek
Copy link
Author

With connect you can pass manual equality checking function, instead of shallowEqual, but there is no way to do it with useSelector, there is no way to fix these kind of cases and turns out I need to rewrite lots of my code, because I have different data structures used on my components. Also transforming to other data types may be overhead. I suggest to add some way to support manual comparison of values for useSelector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants