-
카테고리
-
세부 분야
프론트엔드
-
해결 여부
해결됨
onCreate 이후 property 의 undefind 에러
22.04.06 09:51 작성 조회수 255
0
add 후에 List페이지로 이동하면, 흰화면으로 에러가 출력됩니다.
Home.js 의 프로퍼티에 대해 undefind 가 출력됩니다.
[Uncaught TypeError: Cannot read properties of undefined (reading 'length') at Home.js:15:1]
[ diaryList.length >= 1 ] : 에러 발생하는 부분
useEffect(() => {
if (diaryList.length >= 1) { //에러발생부분
const firstDay = new Date(
curDate.getFullYear(),
curDate.getMonth(),
1
).getTime();
const lastDay = new Date(
curDate.getFullYear(),
curDate.getMonth() + 1,
0
).getTime();
setData(
diaryList.filter((it) => firstDay <= it.date && it.date <= lastDay)
);
}
}, [diaryList, curDate]);
답변을 작성해보세요.
0
이정환 Winterlood
지식공유자2022.04.11
안녕하세요 gwi01304님
강사 이정환입니다.
src/App.js의 reducer의 마지막 라인에 return newState를 추가 해 주셔야 합니다.
0
gwi01304
질문자2022.04.06
codesandbox url
https://codesandbox.io/embed/charming-swartz-917oow?fontsize=14&hidenavigation=1&theme=dark&view=preview
답변 2