A
A
alex4answ2020-12-24 21:01:11
React
alex4answ, 2020-12-24 21:01:11

Why does useSelector return different objects?

Good afternoon, I can not figure out the problem and understand what's wrong. Returns a "new" object each time and re-renders. state.dashboard does not change (other parts of the store change, reducers are clean, everything is as it should be) in redux devtool it is clear that the dashboard does not change, Dashboard in state has an interface:

useSelector(state => state.dashboard);


interface DashboardState {
  from: Date;
  to: Date;
}


Why does a selector return a new object?
After all, I take values ​​from the store without creating a new object.

If you add shallowEqual, then everything is fine and works as it should, no re-renders

. Or if you return not the whole object, but all its parts:
const from = useSelector(state => state.dashboard.from);
const to = useSelector(state => state.dashboard.to);

Everything works, but why the state.dashboard is changing, I can’t understand

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question