강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

ts님의 프로필 이미지
ts

작성한 질문수

[리뉴얼] React로 NodeBird SNS 만들기

안녕하세요 질문이 있습니다.!

작성

·

341

0

다름이아니라 여기서 배운 next-react api 흐름으로 다른 프로젝트 할려고
tsx로 바꿔서 세팅좀 하고 있는데 에러때문에 너무 힘드네요... 개발도 시작못하고 환경문제때문에.... 혹시 도와주실 수 있을까요?
 

답변 1

0

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

저 에러가 발생하면 안 되는데 에러가 발생하네요. useDispatch 와 dispatch 관련된 코드를 싹 다 지워보고 에러가 나나 봐보세요.

ts님의 프로필 이미지
ts
질문자

Server Error

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.

This error happened while generating the page. Any console logs will be displayed in the terminal window.
 
> 11 |   const {value, sampleLoading} = useSelector((state) => state.api1)
지우면 useSelector 에서 걸려요...ㅠㅠ
ts님의 프로필 이미지
ts
질문자

공통점이있어요 

import React, {useCallback, useState} from "react"; 이 hooks은 안그러는데
import {useDispatch, useSelector} from "react-redux"; react-redux 훅이 안되는거같아요
ts님의 프로필 이미지
ts
질문자

그 혹시나해서 _app.tsx 에

export default wrapper.withRedux(MyApp); 이거 감싸줬는데 이런 문구가 뜨네요 
4. WrappedApp은 withRedux(MyApp) { initialState: undefined, initialStateFromGSPorGSSR: undefined }로 새 스토어를 생성했습니다.
오류: 잘못된 후크 호출입니다. 후크는 함수 구성 요소의 본문 내부에서만 호출할 수 있습니다. 다음 이유 중 하나로 인해 발생할 수 있습니다.
1. React와 렌더러(예: React DOM)의 버전이 일치하지 않을 수 있습니다.
2. Hooks의 규칙을 위반할 수 있습니다.
3. React의 복사본이 두 개 이상 있을 수 있습니다.
제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

next-redux-wrapper 세팅문제로 보입니다. 오타가 있을것 같은데 관련 코드들 보여주세요.

ts님의 프로필 이미지
ts
질문자

ts님의 프로필 이미지
ts
질문자

이것도 해봤는데 

ReferenceError: window is not defined

    at Object.<anonymous> (C:\Users\Quantum\IdeaProjects\openAPI\frontend\my-app\node_modules\react-dom\index.js:40:1)

    at Module._compile (node:internal/modules/cjs/loader:1101:14)

    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

    at Module.load (node:internal/modules/cjs/loader:981:32)

    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

    at Module.require (node:internal/modules/cjs/loader:1005:19)

    at require (node:internal/modules/cjs/helpers:102:18) 가 뜨네요...

기존 nodebird에도 똑같이 넣어봤는데 그건 안뜨는듯해요...

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

next-redux-wrapper, redux, react-redux 버전문제 같네요. 제 강좌 코드는 저랑 버전이 같아야 똑같이 돌아갈겁니다.

ts님의 프로필 이미지
ts
질문자

일단 _app.tsx 파일에서  withRedux(app) 에 withRedux 메소드를 인식을 못하는거였어요 그 다음에러가 또 나오네요 근데..

계속 엉켜서 그냥 기존 포맷으로 잡아야겠어요.. ㅋㅋ 역시 버전, 환경문제... 삽파는 구간 ㅠㅠ 

제가  프론트는 제로초님 강의 따라해본 것 밖에없어서... 버전, 환경설정 맞추는게 힘드네요 프론트를 많이 안다루다보니...   

버전, 환경설정 관련해서 팁이 있나요..ㅠ

 

 

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

그냥 기존에 잘 되어있는 소스 활용하시는 게 좋습니다. 그러면서 하나씩 버전을 올려보면서 문제 생겼을 때 해결하면서 넘어가야 합니다. 한번에 버전을 쫙 올려버리면 해결하기 어려워집니다.

ts님의 프로필 이미지
ts
질문자

아 그렇군요 답변감사합니다.

ts님의 프로필 이미지
ts

작성한 질문수

질문하기