useEffect(() => {
resetAll();
}, [resetAll]);
이렇게 코드를 만들면 Maximum update depth exceeded 오류가 뜬다.
Maximum update depth exceeded오류란? 컴포넌트가 업데이트 무한 루프에 빠지는 것이다.
위의 코드같은 경우는 useEffect의 의존성에 동일한 함수를 넣었기 때문에 useEffect가 렌더링되면 의존성의 함수가 새로운것으로 되고 그럼 또 useEffect를 발생하고...무한루프에 빠지게 되기 때문에 잘못된 것이다.
useEffect(() => {
resetAll();
}, []); // 처음렌더링 될 때만 콜백을 하거나
useEffect(() => {
resetAll();
}, [parameter]); //다른 의존성을 넣어줘야 한다| [React][에러해결] Objects are not valid as a React child (found: object with keys {_h, _i, _j, _k}). (0) | 2023.11.07 |
|---|---|
| [React][에러해결] Execution failed for task ':app:installDebug' (0) | 2023.11.06 |
| [React native] 사용자의 기기 정보 가져오기 (0) | 2023.11.06 |
| [React][에러해결] Text strings must be rendered within a <Text> component (0) | 2023.11.06 |
| [React][에러해결] 함수에서 useState사용시 Invalid hook call (0) | 2023.11.06 |
댓글 영역