Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Images not mapping correctly in Reactjs

In React component I have an array of objects:

const books = [
  {
    id: 1,
    name: "The Chrysalids",
    author: "John Wyndham",
    image: "chrysalids",
  },
  {
    id: 2,
    name: "In Cold Blood",
    author: "Truman Capote",
    image: "in-cold-blood",
  },
  {
    id: 3,
    name: "Jane Eyre",
    author: "Charlotte Brontë",
    image: "jane-eyre",
  },
];

And I have mapped it like this:

<div className="row">
        {books.map((book) => (
          <BookComponent
            key={book.id}
            name={book.name}
            author={book.author}
            alt={book.name}
            src={require("./assets/images/" + book.image + ".png")}
          />
        ))}
      </div>

Everything works fine, but the image is not working in html, and the src of img tag is displayed like this:

<img src="[object Module]" alt="The Chrysalids">

Also, the path to image directory is './assets/images/'.

EDIT: Thank you all, the .default property solved the problem.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!