개발공부/React 에러
useEffect 에러 (useMemo)
김놀먹
2022. 5. 19. 22:21
에러코드
React Hook "useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render.
해결방법
공식문서 : Don’t call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function, before any early returns.
=> 반복문, 선언문, 중첩된 함수 내에서 훅을 사용하지 말자! (return문을 사용하면 안됨)
Hook을 최상위에 선언하자!
(useEffect 뿐 아니라 useMemo 등 훅도 마찬가지!)