React - how to access props inside quotes in JSX ?

0 points
Asked by:
Dirask Community

How do I access a value from props to a quoted attribute such as image src?


<img src="svgs/{this.props.svg}" />
1 answer
0 points
Answered by:
Dirask Community

I found two solutions for the problem:

  1. use es6 template literals (``) the following way: 
    • <img src={`svgs/${this.props.svg}`} />
  2. or  put the expression inside curly braces as the entire attribute value like this:
    • <img src={"svgs/" + this.props.svg} />
0 comments Add comment
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂