Skip to content

Proposal: check that useSelector() returning a new object uses an equalityFn #91

@amcsi

Description

@amcsi

As per the docs here, if you pass a selector callback that returns a new object to useSelector() (e.g. useSelector(state => ({prop: state.someReducer.prop})), then the component will re-render on any state change in the entire store. Thus the docs suggest that you pass an equalityFn as the 2nd parameter to useSelector(); typically shallowEqual that is shipped with react-redux.

It would be cool if the eslint plugin provided a way to enforce this. My colleagues wrote a bunch of useSelector() calls with selectors returning new callbacks, without passing a 2nd argument (shallowEqual).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions