ReactAdvanced#effects#debugging

What causes an infinite re-render loop?

Setting state unconditionally during render or in an effect whose dependency changes on every render — for example a new object or array literal in the dependency array.

Example
// loop
useEffect(() => setCount(count + 1));
// loop: new object each render
useEffect(() => load(), [{ page }]);
// fix
useEffect(() => load(), [page]);

Related Questions

1
ReactIntermediate#state#patterns

What is lifting state up?

Open
2
ReactIntermediate#patterns#context

What is prop drilling and how do you avoid it?

Open
3
ReactBeginner#patterns

What is the children prop and composition?

Open