InterviewHubPRO
Section Overview
Q57

Question 57 of 445

Part 1: Core React, JSX & Component Architecture (1 - 77)

13%
React & Modern Frontend (445 Qs)•Part 1: Core React, JSX & Component Architecture (1 - 77)

How do you access props in attribute quotes?

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}`} />