HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptreactCritical

Access props inside quotes in React JSX

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
jsxpropsaccessquotesinsidereact

Problem

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

For example:




The resulting HTML output is:


Solution

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:


Context

Stack Overflow Q#21668025, score: 513

Revisions (0)

No revisions yet.