1

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.

2
  • Is there any error log in browsers console? Commented Apr 2, 2022 at 15:38
  • @SurajSanwal actually no . they just don't show up. Commented Apr 2, 2022 at 20:06

2 Answers 2

1

You may need to pass image like this

 `url(${category.bgImage})`
Sign up to request clarification or add additional context in comments.

Comments

0

Try adding background Images like this:

backroundImage : 'url('+category.bgImage+')'

1 Comment

Why the + before and after the quotes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.