Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  5] [ 5]  / answers: 1 / hits: 128110  / 10 Years ago, mon, february 10, 2014, 12:00:00

In JSX, how do you reference a value from props from inside a quoted attribute value?



For example:



<img className=image src=images/{this.props.image} />


The resulting HTML output is:



<img class=image src=images/{this.props.image}>

More From » reactjs

 Answers
57

React (or JSX) doesn't support variable interpolation inside an attribute value, but you can put any JS expression inside curly braces as the entire attribute value, so this works:



<img className=image src={images/ + this.props.image} />

[#72624] Saturday, February 8, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myrap

Total Points: 407
Total Questions: 105
Total Answers: 109

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
myrap questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Wed, Jan 15, 20, 00:00, 4 Years ago
Thu, Oct 24, 19, 00:00, 5 Years ago
Thu, Oct 3, 19, 00:00, 5 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;