import React from "react";
const Image = ({ name }) => {
try {
// Import image on demand
const image = require(`assets/${name}`);
// If the image doesn't exist. return null
if (!image) return null;
return <img src={image.default} />;
} catch (error) {
console.log(`Image with name "${name}" does not exist`);
return null;
}
};
export default Image;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter