[React] TypeError: Cannot read properties of undefined (reading 'image') 오류

2022. 12. 28. 16:32·🍞 FrontEnd/React

오류 상황

사진을 넣기 위해 서버에서 받아온 이미지 링크를 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

 

저작자표시 (새창열림)

'🍞 FrontEnd > React' 카테고리의 다른 글

[React] 비디오 업로드(multipart/form-data) 기능  (0) 2022.12.29
[React] Expected an assignment or function call and instead saw an expression no-unused-expressions 오류  (0) 2022.12.28
[React] 로그인, 로그아웃, 회원가입 구현 with Redux  (0) 2022.12.24
[React/Node.js] 프론트 서버와 백 서버 한 번에 키기  (0) 2022.12.19
[React/Node.js] CORS 이슈, Proxy 설정  (0) 2022.12.19
'🍞 FrontEnd/React' 카테고리의 다른 글
  • [React] 비디오 업로드(multipart/form-data) 기능
  • [React] Expected an assignment or function call and instead saw an expression no-unused-expressions 오류
  • [React] 로그인, 로그아웃, 회원가입 구현 with Redux
  • [React/Node.js] 프론트 서버와 백 서버 한 번에 키기
박빵이
박빵이
2025년에도 갓생살기
  • 박빵이
    기억보다 기록
    박빵이
  • 전체
    오늘
    어제
    • 분류 전체보기 (337)
      • 🍞 FrontEnd (97)
        • HTML+CSS (4)
        • JavaScript (17)
        • TypeScript (4)
        • React (52)
        • Next.js (2)
        • Android (15)
      • 🍞 BackEnd (24)
        • Java (15)
        • Node.js (6)
        • Spring (1)
      • 🍞 Cloud & Infra (0)
        • AWS SAA (0)
        • Microsoft Azure (0)
      • 🍞 Algorithm (147)
        • C++ (4)
        • Baekjoon (41)
        • Programmers (97)
      • 🍞 Computer Science (18)
        • 운영체제 (1)
        • 데이터 통신 (6)
        • 네트워크 (6)
        • 데이터베이스 (1)
      • 🍞 대외활동 & 부트캠프 (42)
        • 삼성 청년 SW 아카데미 (1)
        • LG유플러스 유레카 (0)
        • 한국대학생IT경영학회 (1)
        • IT연합동아리 UMC (17)
        • 길벗 블로깅 멘토 (18)
        • IT연합동아리 피로그래밍 (3)
        • 개발 컨퍼런스 (2)
  • 블로그 메뉴

    • Admin
  • 링크

    • GitHub
  • 인기 글

  • 태그

    유니온파인드
    react
    level1
    Java
    안드로이드
    umc
    알고리즘
    Front
    level2
    map
    프로그래머스
    코딩자율학습
    길벗 블로깅 멘토링
    Android
    길벗 블로깅 멘토
    JavaScript
    위상정렬
    C++
    코틀린
    백준
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
박빵이
[React] TypeError: Cannot read properties of undefined (reading 'image') 오류
상단으로

티스토리툴바