inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

게시글 구현하기

state is not defined 에러가 뜹니다

해결된 질문

722

정현영

작성한 질문수 7

0

이 에러는 왜 발생한 건가요?

구글에 검색도 해봤는데 안나오네요

도와주세요 ㅠ

reducers/user.js 코드입니다

export const initialState = {

}

export const loginAction = (data) => {
    return {
        type: 'LOG_IN',
        data,
    }
}

export const logoutAction = () => {
    return {
        type: 'LOG_OUT',
    }
}

const reducer = (State = initialState, action) => {
    switch (action.type) {
        case 'LOG_IN': {
            return {
                ...state,
                isLoggedIn: true,
                user: action.data,
            };
        }
        case 'LOG_OUT': {
            return {
                ...state,
                isLoggedIn: false,
                user: null,
            };
        }
        default:
            return state;

    }
};

export default reducer;

터미널창 오류 메세지 입니다

error - reducers/user.js (37:12) @ reducer

error - ReferenceError: state is not defined

at reducer (webpack-internal:///./reducers/user.js:39:13)

at /Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/redux/lib/redux.js:476:24

at Array.forEach (<anonymous>)

at assertReducerShape (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/redux/lib/redux.js:474:25)

at combineReducers (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/redux/lib/redux.js:539:5)

at eval (webpack-internal:///./reducers/index.js:15:75)

at Object../reducers/index.js (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/.next/server/pages/_app.js:33:1)

at __webpack_require__ (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/.next/server/webpack-runtime.js:33:42)

at eval (webpack-internal:///./store/configureStore.js:9:67)

at Object../store/configureStore.js (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/.next/server/pages/_app.js:66:1) {

page: '/'

}

35 | }

36 | default:

> 37 | return state;

| ^

38 |

39 | }

40 | };

event - compiled client and server successfully in 100 ms (1518 modules)

4. WrappedApp created new store with withRedux(NodeBird) { initialState: undefined, initialStateFromGSPorGSSR: undefined }

ReferenceError: state is not defined

at reducer (webpack-internal:///./reducers/user.js:39:13)

at /Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/redux/lib/redux.js:476:24

at Array.forEach (<anonymous>)

at assertReducerShape (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/redux/lib/redux.js:474:25)

at combineReducers (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/redux/lib/redux.js:539:5)

at eval (webpack-internal:///./reducers/index.js:15:75)

at Object../reducers/index.js (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/.next/server/pages/_app.js:33:1)

at __webpack_require__ (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/.next/server/webpack-runtime.js:33:42)

at eval (webpack-internal:///./store/configureStore.js:9:67)

at Object../store/configureStore.js (/Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/.next/server/pages/_app.js:66:1)

 

http://localhost:3060 에 뜬 오류 입니다

Server Error

ReferenceError: state is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Source

reducers/user.js (35:12) @ reducer

  33 |     }
  34 |     default:
> 35 |         return state;
     |        ^
  36 | 
  37 | }
  38 | };

react redux node.js express next.js

답변 1

0

제로초(조현영)

제발 코드도 같이 올려주세요...

0

정현영

죄송합니다 ㅠㅠ 수정했어요

도와주세요

0

제로초(조현영)

State = initialState 가 아니라 state = initialState입니다.

변수 선언을 대문자로 하셨어요

0

정현영

이럴수가!!

state에서 오타가 났었네요

다음부턴 제대로 살펴보겠습니다 ㅠㅠ

감사합니다!! ㅠㅠㅠ

넥스트 버젼 질문

0

78

2

로그인시 401 Unauthorized 오류가 뜹니다

0

89

1

무한 스크롤 중 스크롤 튐 현상

0

175

1

특정 페이지 접근을 막고 싶을 때

0

103

2

createGlobalStyle의 위치와 영향범위

0

96

2

인라인 스타일 리렌더링 관련

0

91

2

vsc 에서 npm init 설치시 오류

0

146

2

nextjs 15버전 사용 가능할까요?

0

158

1

화면 새로고침 문의

0

121

1

RTK에서 draft, state 차이가 있나요?

0

153

2

Next 14 사용해도 될까요?

0

452

1

next, node 버전 / 폴더 구조 질문 드립니다.

0

349

1

url 오류 질문있습니다

0

211

1

ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out

0

373

1

sudo certbot --nginx 에러

0

1275

2

Minified React error 콘솔에러 (hydrate)

0

470

1

카카오 공유했을 때 이전에 작성했던 글이 나오는 버그

0

247

1

프론트서버 배포 후 EADDRINUSE에러 발생

0

327

1

npm run build 에러

0

518

1

front 서버 npm run build 중에 발생한 에러들

0

382

1

서버 실행하고 브라우저로 들어갔을때 404에러

0

338

2

css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.

0

288

1

팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.

0

239

2

해시태그 검색에서 throttle에 관해 질문있습니다.

0

201

1