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

110
Views
issue on showing images for relative formats (reactJS)

I have following code.

    const documents = [
      {
      id: 309,
      name: "sample.pdf",
      hash: "ce01b860a0b92750d922e900a5a8800c",
      ext: ".pdf",
      mime: "application/pdf",
      url:
        "https://realestream.nyc3.digitaloceanspaces.com/ce01b860a0b92750d922e900a5a8800c.pdf",
     },
     {
      id: 165,
      name: "mortgage_financing.png",
      hash: "fe4b75488e35c6f84baf428f7043522e",
      ext: ".png",
      mime: "image/png",
      url:
        "https://realestream.nyc3.digitaloceanspaces.com/fe4b75488e35c6f84baf428f7043522e.png",
      },
      {
      id: 310,
      name: "wordFile.docx",
      hash: "5c8034f2ed8f8bebbb3cfdceadab8123",
      ext: ".docx",
      mime:
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
      url:
        "https://realestream.nyc3.digitaloceanspaces.com/5c8034f2ed8f8bebbb3cfdceadab8123.docx",
      }
    ];

    return (
     <div className="App">
      {documents.map((o) => (
        <div>
          <a href={o.url} target="_blank" rel="noreferrer">
            {o.name}
          </a>
          <img src={`./assets/${o.ext.substring(1)}.png`} alt="file" />
        </div>
      ))}
     </div>
    );

I am trying to show for each format relevant image, but it's not working, please help me to fix this broken image error. I try even like this src=require(./assets/${o.ext.substring(1)}.png).default} , but it's not helped.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Compiled code will look into /public to find your images. You should move your assets to /public instead of src. (manually or by bundle tool)

about 4 years ago · Juan Pablo Isaza Report
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!