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

189
Views
Dynamic background image for reusable components using inline style

I have an assets.js file that I use to handle images and videos like this.

import Bag from "./Bag.png";
import World from "./World.png";

export default {
  World,
  Bag,
};

I also have a parent component let's call A. The component renders a sub-component let's call B twice. Each time with a different background image and different text. My initial approach was to create an object like this

import assets from "../../assets/assets";

const category = [
  {
    type: "For Domestic",
    bgImage: assets.Bag,
  },
  {
    type: "For International",
    bgImage: assets.World,
  },
];

This object is what I would pass to the child component as props like

<B  category={category[0]} />
<B  category={category[1]} />

Now in the child component B, this was my initial approach

const Trips = ({category }) => {
return(
  <div
      className="Trips__container flex__container-v"
      style={{
        backgroundColor: theme.tripsColor,
        backroundImage : category.bgImage,
      }}
    >
    </div>
)
}

I did import everything correctly and passed down the components correctly. However, my images don't show up as the background. What am I doing wrong? Background colors work well and also other inline CSS works. I don't get what is different for background images.

Any other suggestions or a different approach are welcome.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You may need to pass image like this

 `url(${category.bgImage})`
about 4 years ago · Juan Pablo Isaza Report

0

Try adding background Images like this:

backroundImage : 'url('+category.bgImage+')'
about 4 years ago · Juan Pablo Isaza 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!