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

423
Visualizações
image tag - how to put on an ICON (not string - NOT URL) in case of url failure?

I am using React.js as Frontend framework,

I have an icon from antd, and I want to put it in the 'alt' prop of an image tag, so in case that the url I pass there will be null - it will go to put the icon there.

I tried using 'alt' but it only accepts string. is it possible to put there an icon? (like one from antd?)

to emphasize - I want to add it as - <Image alt={<StepBackwardOutlined />}

as in in an actual icon and NOT AS A URL.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use the onerror attribute.

From the docs:

<img src="imagefound.gif" onerror="this.onerror=null;this.src='logoIcon.jpg';" />

Here logoIcon.jpg is the icon path.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use on onError. Inside onError you can create a function outside the main return for ex:-

const onErrorImage = ((e) => {
  e.target.src = <StepBackwardOutlined />
})

<img onError={onErrorImage} />

I never tried it with a component....and i never saw someone using it....so i am not sure that it will work or not.

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