in React JS by
Q:

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}`} />
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Jan 31 in React JS by Robindeniel
0 votes
asked Oct 7, 2020 in Ansible by Robindeniel
0 votes
asked Mar 1, 2020 in React JS by RShastri
0 votes
0 votes
asked May 20, 2020 in React JS by SakshiSharma
0 votes
asked Mar 2, 2020 in React JS by RShastri
0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
...