question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useSelector returns new value on each call even equalityFn returns true

See original GitHub issue

What is the current behavior?

  1. Open https://codesandbox.io/s/serene-franklin-pjkhu?file=/src/App.js
  2. Press button
  3. 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:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
markeriksoncommented, Mar 23, 2021
3reactions
otakustaycommented, Dec 3, 2020

@nightpool I have created #1660 days ago, waiting for a review or merge

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found