본문 바로가기
회고/Today I Learn

Warning: Cannot update a component (`*`) while rendering a different component (`*`). To locate the bad setState() call inside `*`, follow the stack trace as described in

by 김첨지 2023. 9. 20.

 

Warning: Cannot update a component (`Router`) while rendering a different component (`SearchContainer`). To locate the bad setState() call inside `SearchContainer`, follow the stack trace as described in

https://reactjs.org/link/setstate-in-render  

 

 

아래와 같이 되어있는 코드를

  router.replace(pathname + "?" + queryString);

 

useEffect를 사용하여 해결하였다.

  useEffect(() => {
    router.replace(pathname + "?" + queryString);
  }, []);

 

 

Reference

https://velog.io/@pon06188/Warning-Cannot-update-a-component-A-while-rendering-a-different-component-B.-To-locate-the-bad-setState-call-inside-B-follow-the-stack-trace-as-described-in-%EC%97%90%EB%9F%AC-%ED%95%B4%EA%B2%B0