Skip to main content
InterviewHubPRO
Section Overview
Q57

Question 57 of 407

General

14%
React Core & Hooks (407 Qs)•General

How do you access props in attribute quotes?

mid LevelCode ExampleComponents

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

jsx
<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:

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

Using template strings will also work:

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