해결된 질문
작성
·
763
·
수정됨
0
http://localhost:3000/에 뜬 오류
TypeError: Cannot read properties of undefined (reading 'user')
This error happened while generating the page. Any console logs will be displayed in the terminal window.
components/AppLayout.js (15:52) @ eval
13 |
14 | const AppLayout = ({ children }) => {
> 15 | const isLoggedIn = useSelector((state) => state.user.isLoggedIn);
| ^
16 | // const { isLoggedIn } = useSelector(state => state.user);
17 |
18 | return (
components/AppLayout.js (15:36)
Show collapsed frames
터미널에 뜬 오류
TypeError: Cannot read properties of undefined (reading 'user')
at eval (webpack-internal:///./components/AppLayout.js:32:101)
at /Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/react-redux/lib/hooks/useSelector.js:67:26
npm run dev를 하고
http://localhost:3000/ 들어갔더니
이런 오류가 뜨면서 안됩니다.
유저를 왜 읽지 못하는 걸까요?
오류 해결하고 싶습니다 ㅠ
답변 2
0
app.js
import React from 'react';
import Head from 'next/head';
import PropTypes from 'prop-types';
import 'antd/dist/antd.css';
import wrapper from '../store/configureStore';
const NodeBird = ({ Component }) => {
return (
<>
<Head>
<title>NodeBird</title>
</Head>
<Component />
</>
);
};
NodeBird.propTypes = {
Component: PropTypes.elementType.isRequired,
};
export default wrapper.withRedux(NodeBird);
코드입니다 어떤 문제가 있을까요?
package.json은 이렇습니다
강의에서는 리액트-리덕스만 설치했던거 같은데
리덕스를 제가 설치했는데 괜찮을까요?
{
"name": "react-nodebird-front",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next"
},
"author": "winkberry",
"license": "ISC",
"dependencies": {
"@ant-design/icons": "^5.1.4",
"antd": "^4.24.10",
"next": "^9.5.5",
"next-redux-wrapper": "^6.0.2",
"prop-types": "^15.8.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-redux": "^8.1.1",
"redux": "^4.2.1",
"styled-components": "^5.3.10"
},
"devDependencies": {
"eslint": "^8.43.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0"
}
}
https://github.com/ZeroCho/react-nodebird/tree/master/ch3/front
완성 코드는 여기인데 reducers 쪽까지 전부 확인해보세요. return같은 걸 빠뜨리셨을 수도 있습니다.
아예 복사붙여넣기를 해보세요. 오타는 눈으로는 안 찾아집니다.