0

I want to pass props value to inline css.

Here is my code

function Thread(props) {
return(
    <div
    class="img"
    style={{ backgroundImage: "url(Assets/thread-1.webp)" }}
  ></div>
)}

I want to replace the value image url using {props.ThreadImageUrl} But I don't know how to write JS inside inline css.

Here is what I want to achieve.

function Thread(props) {
return(
    <div
    class="img"
    style={{ backgroundImage: {props.ThreadImageUrl} }}
  ></div>
)}

I tried JavaScript string Concatenation but it doesn't work. I'm still newbie to Js and React framework. Glad if someone can help me on this.

1
  • You can use string templates: style={{ backgroundImage: `url(${props.ThreadImageUrl})` }} Commented Sep 2, 2022 at 8:48

1 Answer 1

1

You should do:

backgroundImage: `url(${props.ThreadImageUrl})`,
Sign up to request clarification or add additional context in comments.

Comments

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.