• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

state is not defined 에러가 뜹니다

23.07.10 21:53 작성 23.07.12 13:07 수정 조회수 398

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 | };

답변 1

답변을 작성해보세요.

0

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

정현영님의 프로필

정현영

질문자

2023.07.12

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

도와주세요

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

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

정현영님의 프로필

정현영

질문자

2023.07.12

이럴수가!!

state에서 오타가 났었네요

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

감사합니다!! ㅠㅠㅠ