I have products in JSON format that are fetched and shown in the frontend. In my products.json there is an image URL for each products, but only some have image URLs in them, others are empty. When I am looping the data in react I always get error in my react app saying Cannot read property of null in the <img/> tag, how do I write a logic that only renders the image when there is an image source else just return an empty div?
<ul>
{this.state.items.map((items, index) => {
return (
<li className="ProductList-product" key={items.id}>
<h3>{items.title}</h3>
<p>{items.description}</p>
<div className="price-box">
<p>from: {items.price} $</p>
</div>
<div>
{<img src={items.photo} alt=""/>}
{/* {console.log(items.photo.id)} */}
</div>
</li>
);
})}
</ul>