Skip to content Skip to sidebar Skip to footer

Cannot Display Images In Reactjs?

I have multiple images instead of importing each image in my content.js like this eg: import myimg1 from './myimg1.png' import myimg2 from './myimg2.png' import myimg3 from './myim

Solution 1:

See there is no class named images in your images.js, so

import images from'./images'

will do nothing in content.js...So try this way

images.js

import java from'./images/java.png';
import logo from'./images/logo.png';

export {
    java,
    logo
}

content.js

import React, { Component } from'react';
import { java, logo } from'./images';

<img src={java} alt="" height="65" width="65">
<img src={logo} alt="" height="65" width="65">

Solution 2:

the export default is just used for when there is only one import function, in your case you should do export without default

export {
    java,
    logo,
    dsa,
    dl,
    ds,
    boy,
    ml,
    neural,
    phone
}

Then, in your file, you'd import all inside brackets

import { java, logo, dsa.. } from'./yourFilePath'

Post a Comment for "Cannot Display Images In Reactjs?"