Languages
[Edit]
EN

React - import image from public folder

0 points
Created by:
Anisha-Kidd
652

In this article, we would like to show you how to import image from public folder in React.

Quick solution:

<img src="/image.jpg" />

 

Practical example

In this example, we simply specify the image name (image.jpg) with preceding slash as an img source. React will know, that the image is in the public folder.

import React from 'react';

const MyComponent = () => {
  return (
    <div>
      <img src="/image.jpg" />
    </div>
  );
};

export default MyComponent;

Note:

If you have images/ folder inside public/ directory, just specify the image src as follows:

<img src="/images/image.jpg" />
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join