0 votes
in ReactJS by

How do you access props in attribute quotes?

1 Answer

0 votes
by

React (or JSX) doesn't support variable interpolation inside an attribute value. The below representation won't work:

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

But you can put any JS expression inside curly braces as the entire attribute value. So the below expression works:

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

Using template strings will also work:

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

Related questions

0 votes
asked Dec 19, 2023 in ReactJS by john ganales
0 votes
0 votes
asked Oct 31, 2023 in ReactJS by AdilsonLima
...