Friday, 5 May 2017

javascript - Access props inside quotes in React JSX



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




For example:






The resulting HTML output is:






Answer



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:





No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...