Ways to import images to your  react app

Ways to import images to your react app

·

2 min read

Hello👋 beautiful developers, guess you doing great.

Importing images on react app is a big wahala (problem), I don't know about some people but it is for me. Mostly when I try to display it dynamically using an array.

Let me not divert from the topic:- There are different ways to import an image to react either by setting up your image under the Public folder or Src folder both ways display.

Public Folder

  • Here you input the image as you will do on your HTML

How it is typed on text-editor

public way.png

Display of the image on the browser display public way.png

  • It also works when you try to display it dynamically too

How it is typed on text-editor texteditor2.png Display of the image on the browser crystal.png

Src Folder

Creating your image in Src Folder is different you use import, require, or Reactcomponent keyword.

i. Using Import Keyword

How it is typed on text-editor

src.png Display of the image on the browser src2.png

ii. Using require Keyword

How it is typed on text-editor src img3.png Display of the image on the browser src3 img.png

iii. Using ReactComponent Keyword

How it is typed on text-editor

twitterSRC.png

Display of the image on the browser

twitterSRC image.png

iv. Creating a file and putting all your images inside

a. first you create the file write your data(images)

b. You import the images to the app.js so it will display on your browser

How it is typed on text-editor

a.

textfile.png

b.

textfile2.png

Display of the image on the browser

textfileimg.png

It is possible to display your image directly from the site, you can get the address of the image. it has a disadvantage; the network might be slow😡.

How it is typed on text-editor

address text.png

Display of the image on the browser

address img.png

Thank-You-GIF.gif Contact

LinkedIn , Twitter and Gmail

Did you find this article valuable?

Support Cent Blog </💖> by becoming a sponsor. Any amount is appreciated!

Â