0

I want to add two images 1)java.png 2)neural.png When I try to type in src="java.png" and src="neural.png" it does not load the image. I want to add these images in my content component.

content.js:

class Content extends Component {

  render() {
    return (
      <div> 

                     <div className="col l4">
                            <img src="java.png" alt="Java" height="25" width="25"></img>
                            <h6 className="cardtitle1">NEW LAUNCH</h6>
                            <p className="cardcontent1">JAVA</p><p></p>
                            <p className="cardcontent1">Foundations</p>
                      </div>

                      <div className="col l4">
                            <img src="neural.png" alt="Neural Network" height="25" width="25"></img>
                            <h6 className="cardtitle2">NEW LAUNCH</h6>
                            <p className="cardcontent2">Neural Newtwork</p><p></p>
                            <p className="cardcontent2">Foundations</p>
                      </div>
 </div>
    );
  }
}

export default Content;

The file path looks like this:

enter image description here

In console it shows image could not load: enter image description here

6
  • Are you using create-react-app? Commented Mar 12, 2018 at 4:53
  • @salman.zare Yes Commented Mar 12, 2018 at 4:53
  • Have you imported the image? like this: import java from './java.png'; And then: <img src={java} alt="Java" /> Commented Mar 12, 2018 at 4:56
  • @salman.zare Should I make images.js and then import it ? Commented Mar 12, 2018 at 4:56
  • No, please refer to the following reference: github.com/facebook/create-react-app/blob/master/packages/… Commented Mar 12, 2018 at 4:57

3 Answers 3

2

Actually, there are many ways to handle images in ReactJS.

import Java from './java.png';

then use it like

  <img src={Java} alt="Java" height="25" width="25" />

Also check of this link will help you Unable to load images from local library in React.js

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please help me out here: stackoverflow.com/questions/49229529/…
1

I put all my images in one 'images' folder under the public folder, then anywhere in my project, I can use the following path in img element:

It works fine with my projects initiate with create-react-app especially when I have too many images, then I don't have to import one by one.

Comments

0

try this

 <img src="./java.png" alt="Java" height="25" width="25"></img>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.