에러코드
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 등 훅도 마찬가지!)
'개발공부 > React 에러' 카테고리의 다른 글
import 시 경로가 이상하게 들어오는 문제 (0) | 2022.09.14 |
---|---|
useHistory -> useNavigate (0) | 2022.03.24 |
Switch -> Routes 로 변경 (0) | 2022.03.24 |