redux와 too many render (계속 렌더링 되는 오류)

Hmm·2022년 8월 4일
0

React.js

목록 보기
5/5
post-custom-banner

Uncaught Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

dispatch(changeCalendar(makeCalendar()));

dispatch가 실행되면 다시 렌더링되는데 다시 렌더링되면 또 dispatch가 실행되고 무한 반복에 빠진다. 따라서 첫 렌더링에만 실행되도록 useEffect를 쓰거나 콜백함수를 쓰면 해결된다.

On every render, PaisBody will be executed, it may cause an infinite loop because on each render you dispatch an action that may lead to re-render.
In such cases, you should use useEffect (with dep-array) or useCallback (if you going to share props):
https://stackoverflow.com/questions/57978675/react-hooks-too-many-re-renders-in-pagination-with-redux

  useEffect(() => {
    dispatch(changeCalendar(makeCalendar()));
  }, []);
post-custom-banner

0개의 댓글