🍞 Front-End/React
[React] TypeError: Cannot read properties of undefined (reading 'image') 오류
박빵이
2022. 12. 28. 16:32
오류 상황
사진을 넣기 위해 서버에서 받아온 이미지 링크를 src에 넣었더니 읽어들일 수가 없다고 한다.
이는 이미지 정보를 가져오기 전에, 먼저 화면이 렌더링 되어 undefined가 뜬다고 생각했다!
TypeError: Cannot read properties of undefined (reading 'image')
해결 방법
image가 있다면 렌더링되도록 조건문을 걸어주었다.
// 조건문 걸어준 것
if (VideoDetail.writer) {
return (
<List.Item.Meta
avater={<Avatar src={VideoDetail.writer.image} />}
title={VideoDetail.writer.name}
description
/>
);
}
// 사진이 없다면 loading ...
else {
return <div>...loading</div>;
}
참고)
TypeError: Cannot read properties of undefined (reading 'img') React
Please Guys i need Help, i got this error when i am compiling the code. i put items in a file data.js and it is working for others products but for this One i don't know what i am missing. import R...
stackoverflow.com