Paul Jones
Paul Jones

Reputation: 149

Image not loading in reactjs

I created a project with create-react-app and I'm trying to load an image but I keep getting the same parsing error.

Here is the code:

  1 import React, { Component } from 'react'
  2 import profile from './profile.png'
  3 
  4 class Jumbotron extends Component {
  5     render() {
  6         return (
  7             <div className="container">
  8                 <JumbotronName />
  9                 <JumbotronImg />
 10             </div>
 11         )
 12     }
 13 }
 14 
 15 const JumbotronName = () => {
 16     return (
 17         <div className="container">
 18             <h1>Temp</h1>
 19         </div>
 20     )
 21 }
 22 
 23 const JumbotronImg = () => {
 24     return (
 25         <div className="container">
 26             <img src{profile} alt="Profile" />
 27         </div>
 28     )
 29 }
 30 
 31 export default Jumbotron

Both files (Jumbotron.js and the image) are in the src folder of the create-react-app.

When I run with npm start, i get this parsing error

./src/Jumbotron.js
  Line 26:22:  Parsing error: Unexpected token, expected "..."

  24 |     return (
  25 |         <div className="container">
> 26 |             <img src{profile} alt="Profile" />
     |                      ^
  27 |         </div>
  28 |     )
  29 | }

Any ideas?

EDIT: if I put '...' before profile in line 26 (ex src{...profile}), it will compile but the image will not load

Upvotes: 1

Views: 403

Answers (1)

iLiA
iLiA

Reputation: 3153

you need to write equation sign like this

 <img src={profile} alt="Profile" />

Upvotes: 3

Related Questions