useSelector returns new value on each call even equalityFn returns true
See original GitHub issueWhat is the current behavior?
- Open https://codesandbox.io/s/serene-franklin-pjkhu?file=/src/App.js
- Press button
- Inspect console log
We have some confusing logs in console like:
array equals: true
selector value changed
This indicates the return value of useSelector
changes even its equalityFn
returns true
.
What is the expected behavior?
In DisplayValueList
component, the value mustChange
can change on every press, but the next useSelector
should return a constant value because its selector function returns a static array and its equalityFn
is set to an array equal function, the console log should be clean.
When the first useSelector
is removed, the console output is clean as expected, this is even more confusing to me.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
selector returning different value despite custom equalityFn ...
the selector above initially returns an empty array, but a different one every time and I don't understand why because the equality function ......
Read more >Hooks - React Redux
With useSelector() , returning a new object every time will always force a re-render by default. If you want to retrieve multiple values ......
Read more >redux toolkit useselector | The search engine you control.
Open links in a new tab ... When used with plain state values, the selector will still memoize ... Redux Toolkit, useSelector returns...
Read more >Using the React-Redux useSelector Hook | by John Au-Yeung
The selector function may return any value as a result, not just an object. ... useSelector multiple times with each call returning a...
Read more >Container Component | ThinkBucket
It's easy to accidentally return new object or array references every time, which would cause your component to re-render even if the data ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Released in https://github.com/reduxjs/react-redux/releases/tag/v7.2.3 .
@nightpool I have created #1660 days ago, waiting for a review or merge