A
A
alex4answ2020-12-24 09:15:30
React
alex4answ, 2020-12-24 09:15:30

How to prevent component from re-rendering when redux store changes?

Hello, I've come across something I don't understand.

There is a container component that uses 1 part of the store and changes the other part:

const date = useSelector(state => state.dashboard.date);

useEffect(() => {
  dispatch(getAllHouses());
}, [dispatch, date]);



As a result , when one part of the store that is not used in this component changes (all houses are loaded), the component is re-rendered and useEffect fires again ( although the date is the same, I even return the state part, not a new object from state ) everything slides into an endless render loop, why and how to avoid it?
Do I understand correctly that by changing one part of the store that is not even used at the moment (on the page and components), the tree will be re-rendered starting from the Redux Provider ?

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