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

314
Visualizações
React - load an image from a relative URL (through a web API)

I'm in process of learning react and I've stumbled upon an issue with loading images in my react components. The issue is that some images I'm using are normal raster images that are easy to import, and some are SVGs. The SVGs are loaded through an API that lets me recolor them on the fly like so - /api/svg/some-image.svg/fff,222. My react development server and the API are on different ports so I'm using a proxy to get everything working together for the time being.

The issue is that I can not use the API to load images because react will throw compile errors, or at best won't be able to resolve the URL due to the API being on a different port. Trying to set the background image in CSS will also throw compilation errors.

The "traditional" way throws compile errors

import bgImage from '/api/svg/bg1.svg/000';
<div style={{ backgroundImage: `url(${bgImage})` }}></div>

Trying to somehow force the location.origin into the URL doesn't always properly work too as probably expected.

And so my point is - Is there any way to tell react to just put the specified URL untouched exactly where it is without it trying to import the resource?

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