Home > Enterprise >  Cannot read property 'large' of null
Cannot read property 'large' of null

Time:02-28

I have a graphql request. It works fine, but if the poster is missing I got errors. I tried to fix like this:

<div className="movie__hero">
    <img
       src={ movie.poster.large == null ? "poster" : movie.poster.large }
       alt="Poster"
       className="movie__img"
     />
 </div>

enter image description here

Any ideas to fix the issue?

CodePudding user response:

The error isn't telling you that large is null, it's telling you that poster is null:

src={ movie.poster == null ? "poster" : movie.poster.large }

CodePudding user response:

Based on your error, you need to check if movie.poster is null or not.

src={ movie.poster == null ? "poster" : movie.poster.large }
  • Related