인프런 커뮤니티 질문&답변
onCreate 이후 property 의 undefind 에러
해결된 질문
작성
·
387
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]);
답변 2
0
이정환 Winterlood
지식공유자
안녕하세요 gwi01304님
강사 이정환입니다.
src/App.js의 reducer의 마지막 라인에 return newState를 추가 해 주셔야 합니다.
0
gwi01304
질문자
codesandbox url
https://codesandbox.io/embed/charming-swartz-917oow?fontsize=14&hidenavigation=1&theme=dark&view=preview




