Home > Software design >  React - local image won't load?
React - local image won't load?

Time:06-21

I am attempting to load a local image in React js. Following enter image description here

I have deployed this to Vercel as well as tested locally, so I do not think this is a server issue. I've tried the import method described here as well.

What is wrong here and how can I load a local image?

CodePudding user response:

At the moment I can propose you two options.

  1. Import your image as a component.
    Just place this line of code in the head of your file:
    import {ReactComponent as COMPONENT_NAME} from PATH
    And place this COMPONENT_NAME in your other components. You can apply stying to it, props and etc.
  2. Import your image path.
    import IMAGE_PATH from PATH
    And in your component:
    <img src={IMAGE_PATH} {...options} />
  • Related