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

99
Views
Dynamic src for img tag with javascript

I have a react-app that gets crypto API from some Provider Server and setState in currency variable and shows them in a table. I download each cryptocurrency icon and create a JSON file (cryptoIconSrc) to set img tag src dynamically. icons are SVG. but they don't display on my table.

here I set a condition to find the related icon from the JSON file

currency.map((item) => {
                    let mapItem = item;
                    const temp = cryptoIconSrc.filter((item) => {
                      return item["symbol"] === mapItem["baseAsset"];
                    });

and here I set that related icon to img src

                    <img
                    src={`${temp[0]["src"]}`}
                    width="20px"
                    height="20px"
                    />

but they don't display

I use require("./someDirectory/icon.png") in other sections of my app but in this case require(`${temp[0]["src"]}`) doesn't work and issue an error : module ... not found

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

0

  <img
    src={`${temp[0]["src"]}`}
    key={`${temp[0]["src"]}`}
    width="20px"
    height="20px"
   />

Adding a key prop will do the trick.

about 4 years ago · Juan Pablo Isaza Report

0

It seems like you are using back ticks in your code. That almost never works, try using single quotes. So not:

src={`${temp[0]["src"]}`}

But:

src={'${temp[0]["src"]}'}
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!