Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda