My code looks something like this:
const countersSelector = () => (store) => store.counters;
const MethodOne = () => {
// Method: Object destructuring
const counters = useSelector(countersSelector);
console.log("render MethodOne");
useEffect(() => {
console.log("in useeffect methodone");
}, [counters]);
return (
<div>
<p>{`firstCounter: ${counters}`}</p>
<p>{`renders: ${renderCount}`}</p>
</div>
);
};
export default MethodOne;
This is the full app: https://codesandbox.io/s/redux-useselector-object-destructuring-example-forked-1m87x
And every time counters object is changed (not its value, but the object reference itself), that useEffect() gets triggered.
Can i memoize it somehow, so that counters will only change if the actual values of store.counters change?