EN
React - import image from public folder
0 points
In this article, we would like to show you how to import image from public folder in React.
Quick solution:
xxxxxxxxxx
1
<img src="/image.jpg" />
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.
xxxxxxxxxx
1
import React from 'react';
2
3
const MyComponent = () => {
4
return (
5
<div>
6
<img src="/image.jpg" />
7
</div>
8
);
9
};
10
11
export default MyComponent;
Note:
If you have
images/
folder insidepublic/
directory, just specify the imagesrc
as follows:xxxxxxxxxx
1<img src="/images/image.jpg" />