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.

[Docs]: improve usage of second arg of `useSelector` (equality function)

See original GitHub issue

The documentation talks about using shallowEqual as second argument for comparison (or lodash), although the documentation doesn’t explain what are the arguments of this function and how a user could write their own custom equality function.

Is there a way to improve that part of the documentation?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
markeriksoncommented, Nov 28, 2022

@dwaltrip : tbh it’s a trivial enough function that there’s never been a specific need to document it 😃 (Plus in this case you don’t normally call it directly, you just import it and pass it as the second arg to useSelector.)

But yeah, happy to have a PR!

1reaction
ematipicocommented, Jul 13, 2020

I understand that shallowEqual per se accepts two properties, but when used with useSelector, what’s inside left and right?

By doing some logging, I can see left and right are the portion of the state selected by the selector.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass an additional argument to useSelector
I am calling useSelector successfully from a component, which derives a product name from an id. import { useSelector } from "react-redux"; ...
Read more >
Hooks - React Redux
Use a custom equality function as the equalityFn argument to useSelector() , like: import { useSelector } from 'react-redux'
Read more >
Redux Gotchas — useSelector - Level Up Coding
This is because the equality check is performed on the outcome of state function. The state property counter is indeed getting updated, which ......
Read more >
React-redux useSelector hook and equality checks
useSelector is one of the redux hooks, which really makes life of a dev much more convenient. Usually we use it to get...
Read more >
useselector custom hook | The search engine you control.
We can use the useSelector hook to get the data from the Redux store in a React component. It takes 2 arguments. The...
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