Proposal: check that useSelector() returning a new object uses an equalityFn
amcsi opened this issue · comments
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
).