combineReducers사용할때 오류가 생겨요
546
작성한 질문수 3
에러는 TypeError: Cannot read properties of undefined (reading 'type') 이렇게 출력이 되고
해당 에러가 난 코드는 reducer/user.js의
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'LOG_IN':
이부분 입니다
user.js, post.js에
if (action === undefined){return state}
를 추가해서 수정하려했지만
TypeError: Cannot read properties of undefined (reading 'isLoggedIn')
이렇게 추가로 오류가 발생합니다
어떻게 수정해야할까요..ㅜㅜ
답변 3
0
combineReducers를 사용하기전까지(20강 수강까지)는 잘되었으나 해당부분을 사용하자 에러가 생겼습니다
0
combineReducers 코드 입니다
강사님과는 다르게 index부분이 회색으로 주석 쳐진것처럼 나와요
import {HYDRATE} from "next-redux-wrapper";
import {combineReducers} from "redux";
import user from "./user";
import post from "./post";
const rootReducer = combineReducers({
index: (state = {},action) =>{
switch (action.type){
case HYDRATE:{
return {...state,...action.payload}
}
default:{
return state
}
}
},
user,
post,
})
export default rootReducer
0
https://github.com/ZeroCho/react-nodebird/tree/master/ch3/front
이것과 비교해보셔야 할 것 같습니다. 제 생각에는 pages쪽에서도 호출을 잘못했거나 하는 경우가 있을 수 있습니다.
0
제가 강사님 답변을 정확하게 이해하지 못해서 로그인 관련 코드를 올려보겠습니다
LoginForm.js 코드
const LoginForm = () =>{
const dispatch = useDispatch()
const [id, onChangeId] = useInput('')
const [pw, onChangePw] = useInput('')
const onSubmitForm = useCallback(() => {
console.log(id,pw)
dispatch(LoginAction({id,pw}))
},[id,pw])
----------------------------------------------------
user.js 코드
export const LoginAction = (data) => {
return{
type:'LOG_IN',
data:data,
}
}
const reducer = (state = initialState, action) => {
switch (action.type){
case 'LOG_IN':{
return{
...state,
isLoggedIn: true,
user:action.data
}
}
이렇게 작성하였는데 강의를 돌려봐도 어디가 문제인지 잘 모르겠네요..
0
npm run dev를 하면 화면에 Internal Server Error 고 나오면서 콘솔창에 status 500에러라고 나옵니다
TypeError: Cannot read properties of undefined (reading 'type') 이부분은 터미널에서 확했어요
넥스트 버젼 질문
0
90
2
로그인시 401 Unauthorized 오류가 뜹니다
0
104
1
무한 스크롤 중 스크롤 튐 현상
0
192
1
특정 페이지 접근을 막고 싶을 때
0
116
2
createGlobalStyle의 위치와 영향범위
0
102
2
인라인 스타일 리렌더링 관련
0
97
2
vsc 에서 npm init 설치시 오류
0
157
2
nextjs 15버전 사용 가능할까요?
0
166
1
화면 새로고침 문의
0
129
1
RTK에서 draft, state 차이가 있나요?
0
160
2
Next 14 사용해도 될까요?
0
455
1
next, node 버전 / 폴더 구조 질문 드립니다.
0
358
1
url 오류 질문있습니다
0
214
1
ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out
0
391
1
sudo certbot --nginx 에러
0
1293
2
Minified React error 콘솔에러 (hydrate)
0
477
1
카카오 공유했을 때 이전에 작성했던 글이 나오는 버그
0
255
1
프론트서버 배포 후 EADDRINUSE에러 발생
0
337
1
npm run build 에러
0
525
1
front 서버 npm run build 중에 발생한 에러들
0
398
1
서버 실행하고 브라우저로 들어갔을때 404에러
0
350
2
css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.
0
290
1
팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.
0
249
2
해시태그 검색에서 throttle에 관해 질문있습니다.
0
206
1





