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

home2 게시판 React 게시판 Warning: Invalid hook call 오류

Warning: Invalid hook call 오류

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

    정지은
    참가자
    react.development.js:209 Warning: 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.
    이런 오류가 뜨면서 브라우저 렌더링이 안됩니다.
     
    스크린샷 2023-06-08 오후 6.20.361
    
    
    
    1. 이걸 보면 호환문제는 아닌 것 같고,
    
    
    import React from 'react';
    import ReactDOM from 'react-dom/client';
    import './index.css';
    import App from './App';
    import { Provider } from 'react-redux';
    import store from './store';
    import { BrowserRouter } from 'react-router-dom';
    const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(
    <React.StrictMode>
    <Provider store={store}>
    <BrowserRouter>
    <App/>
    </BrowserRouter>
    </Provider>
    </React.StrictMode>
    );
    import './App.css';
    function App() {
    return (
    <div className="App">
    </div>
     );
    }
    export default App;
    
    
    import {createSlice, configureStore} from '@reduxjs/toolkit'
    //state 만들기
    let hobby = createSlice({
    name: 'hobby',
    initialState: 'dancing'
    })
    //state 등록하기
    export default configureStore({
    reducer:{
    hobby : hobby.reducer
    /*작명: createSlice만든거.reducer */
     }
    })
    import {useSelector} from "react-redux";
    function Cart(){
    let a = useSelector((state)=> state.hobby)
    console.log(a)
    return(a)
    }
    
    
    
    
    전체 코드입니다. 2번처럼 hook 규칙을 어긴것도 아닌것 같고, 3번 중복 설치 문제일까요??
    스크린샷 2023-06-08 오후 6.23.28
    
    정말 찾아도 찾아도 모르겠어요
    
    
     
     
     
     
     
    #86305

    codingapple
    키 마스터
    Cart 컴포넌트 return안에 a말고 html 넣어봅시다
    #86312

    정지은
    참가자
    해결했습니다. 
    <BrowseRouter>를 설치하지 않고 작성한 것이 문제가 되었습니다
    import만 하면 vscode 상으로는 문제가 없어서, 간과했습니다.
    이 오류는 공식문서에 나온 방법으로는 해결이 불가능해서, 혹시 저처럼 리액트라우터를 설치하지 않고, <BrowseRouter>를 작성했다가 페이지를 렌더링을 하는데 오류를 가진 사람들을 위해서 블로그에 포스팅을 하겠습니다.
    읽어주셔서 감사합니다.
    코드 한줄을 쓰더라도 왜 이 코드를 써야하는지 생각하면서 작성하겠습니다
    
    
    
    
    콘솔 오류창을 더 내려보니 이런 문구도 있었습니다. 오류를 더 자세히 읽어야 겠어요!
    react-dom.development.js:18687 The above error occurred in the <BrowserRouter> component:
        at BrowserRouter (http://localhost:3000/static/js/bundle.js:46950:5)
        at Provider (http://localhost:3000/static/js/bundle.js:35586:5)
    
    
    		
    	
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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