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

312
Views
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
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!