Access props inside quotes in React JSX
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} />
If you want to use the es6 template literals, you need braces around the tick marks as well:
<img className="image" src={`images/${this.props.image}`} />
If you're using JSX with Harmony, you could do this:
<img className="image" src={`images/${this.props.image}`} />
Here you are writing the value of src
as an expression.
Instead of adding variables and strings, you can use the ES6 template strings! Here is an example:
<img className="image" src={`images/${this.props.image}`} />
As for all other JavaScript components inside JSX, use template strings inside of curly braces. To "inject" a variable use a dollar sign followed by curly braces containing the variable you would like to inject. For example:
{`string ${variable} another string`}