Languages

React - how to access props inside quotes in JSX ?

0 points
Asked by:
Dirask Community
5460

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

example:

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

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.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join