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

Wdyr ignores equality function in useSelector #190

Open
RobertGoins opened this issue Apr 16, 2021 · 3 comments
Open

Wdyr ignores equality function in useSelector #190

RobertGoins opened this issue Apr 16, 2021 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Low priority

Comments

@RobertGoins
Copy link

When using wdyr I noticed that it reports unnecessary renders caused by useSelector with an equality function even though the equality function causes the render to be avoided. Looking at the code it looks like wdyr does not consider the result of the equality function.

An example:

useSelector(someSelector, (prev, next) => true);

@vzaidman vzaidman added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Low priority labels Apr 28, 2021
@vzaidman
Copy link
Collaborator

Good point.
useSelector is a custom hook, and as such, we only consider it's result.
How would you expect it to work?
I remind you that we only track custom hooks since you added them in the options, so probably we need to extend the options:

import React from 'react';

if (process.env.NODE_ENV === 'development') {
  const whyDidYouRender = require('@welldone-software/why-did-you-render');
  const ReactRedux = require('react-redux');
  whyDidYouRender(React, {
    trackAllPureComponents: true,
    trackExtraHooks: [
      [ReactRedux, 'useSelector']
    ]
  });
}

@DouglasPds
Copy link

I could not reproduce this error. When I used the example given by Robert (prev, next) => true, or using the shallowEqual of the Redux as equalityFn, the wdyr does not show the message of rerendering.

I don't know if I understand this error correctly.

@trickeyd
Copy link

trickeyd commented Nov 1, 2022

I am getting this issue too, and it is making use of wdyr rather difficult to use unfortunately.

@RobertGoins - did you find a way round this?

@DouglasPds - when you tested, are you sure that you weren't also returning the same values? The hook will check for strict equality (===) before invoking the equality function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Low priority
Projects
None yet
Development

No branches or pull requests

4 participants