dimanche 17 mars 2019

JavaScript Check if File exists, if not then

I am working on a table where I need to return images in the first column. The below code works fine except if it doesn't find the image then I get an error.

I would like to check if the file exists and if it does not exist, to return a default image. How should I approach this?

Thanks,

              Cell: cellProps => {
                const imgPath = cellProps.row.ExternalID;
                return (
                  <img
                    src={require(`../images/${imgPath}.png`)}
                    alt=""
                  />
                );
              }

Aucun commentaire:

Enregistrer un commentaire