• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 React 게시판 useEffect쓰는데 왜이런게 나오는지 모르겠네요.

useEffect쓰는데 왜이런게 나오는지 모르겠네요.

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #28496

    조승엽
    참가자

     let[count,setCount] = useState(0);
      let[age,setAge] = useState(20);

    <button onClick={()=>{
            setCount(count+1)
            useEffect(()=>{
              if(count !=0 && count<3){          
                setAge(age+1)
                }          
              },[count])
           
            }}>누르면한살먹기</button>

     

    이렇게 입력하는 수업중에 콘솔창에 이런 에러가 뜨네요.

    react-dom.development.js:14906 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem. at Object.throwInvalidHookError (react-dom.development.js:14906:1) at useEffect (react.development.js:1520:1) at App.js:33:1 at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1) at invokeGuardedCallback (react-dom.development.js:4056:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1) at executeDispatch (react-dom.development.js:8243:1) at processDispatchQueueItemsInOrder (react-dom.development.js:8275:1) at processDispatchQueue (react-dom.development.js:8288:1)

     

    #28505

    조승엽
    참가자

    useEffect를 잘못되 위치에 썻었네요.

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠