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

167
Views
React - BackgroundImage with data doesn't display

I'm using React and i'm trying to inject dynamically a backgroundImage from a data.json, so i'm writing my backgroundImage directly in the jsx, as inline-style, but the background don't wants to show up. I've already checked the source, and it's correct !

I'll give you a code sample and a screen of my console to show you that my path for the backgroundImage is correct !

const Card = ({ artCard }) => {
const backgroundThumbnail = artCard.images.thumbnail;
console.log(backgroundThumbnail);
return (
<React.Fragment>
  <div
    className="card"
    style={{
      backgroundImage: `url(${backgroundThumbnail})`,
      backgroundRepeat: "no-repeat",
      backgroundSize: "cover",
      backgroundPosition: "center",
      minHeight: "300px",
      minWidth: "300px",
    }}
  >
    {/* <h3>{artCard.name}</h3> */}
    {/* <h4>{artCard.artist.name}</h4> */}
  </div>
</React.Fragment>
);
};

Screenshot ๐Ÿ‘‡ google console

about 4 years ago ยท Santiago Trujillo
2 answers
Answer question

0

You forgot to add a double quote inside the bracket, try this:

backgroundImage: `url("${backgroundThumbnail}")`

Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/background-image

about 4 years ago ยท Santiago Trujillo Report

0

Alright, found the problem, my images were not on the public folder, so react won't read it !

about 4 years ago ยท Santiago Trujillo 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!