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

176
Views
Why is the first method working but second isn't?

First Method:

const getWeatherIcon = (iconParameter) => {
   const icon = `https://openweathermap.org/img/wn/${iconParameter}@2x.png`
   return <img src={icon} alt={iconParameter} />
  }

<div className="weathericon">
       {getWeatherIcon(weather.weather[0].icon)} //Ex: weather.weather[0].icon=50n
</div>

Second Method:

const getWeatherIcon = (iconParameter) => {
    const icon = `assets/weather/${iconParameter}.svg`
    return <img src={icon} alt={iconParameter} />
  }

<div className="weathericon">
     {getWeatherIcon(weather.weather[0].main)} //Ex: weather.weather[0].main=Haze
</div>

Here Is My Project Directory

src
│   App.js
│   index.css
│   index.js   
│
└───assets
    └───weather
    |  |    Haze.svg 
    │  |    Clear.svg
    │  |    Rain.svg
    |  
    └───bg
        |   file111.png
        |   file112.png

Ignore following

It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details.

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

0

You file path is not correct try to use ./assets/weather to give proper path

about 4 years ago · Juan Pablo Isaza Report

0

This Worked!!

const getWeatherIcon = (iconParameter) => {
    const icon = `${iconParameter}.svg`
    return < img src={icon} alt={iconParameter} width='100px' />
  }

<div className="weathericon">
                  {getWeatherIcon(weather.weather[0].main)}//Haze, Clear etc.
                </div>

File System:

src
│   App.js
│   index.css
│   index.js   
│
└───assets
│   └───bg
│   |   file111.png
│   |   file112.png
│
│        
public
│   Clear.svg
│   Clouds.svg
│   Rain.svg
│   Haze.svg
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!