I have a folder with images of wines all named with their code (ie: FMP-HTR17) and want to display the associated image if it exists, but if the image isn't in the folder I want to render a stock photo instead.
Right now I have a ternary operation which I thought would return false if the image wasn't in the folder, but since I have a code for the wine it returns true (obviously). But I can't figure out how to check to see if the image exists!
// Finds image with Code if available:
{ `/images/bottle/${this.props.Code}.png` ? <Image className="cardImage" src={`/images/bottle/${this.props.Code}.png`}/>
:
// Else renders Stock Image:
<Image className="cardImage"src='/images/StockRED.png' />
}
How do I see if a file exists with the name I'm looking for?