Where to Store Images in React App | Upbeat Code - importing images dynamically

PHOTO EMBED

Thu May 05 2022 07:13:36 GMT+0000 (Coordinated Universal Time)

Saved by @Jude∗ #jsx

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;
content_copyCOPY

https://www.upbeatcode.com/react/where-to-store-images-in-react-app/