Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to concatenate an img src in React?

This might be a silly question but I'm trying to concatenate the source of an image in React to be rendered on the screen, but it's not working.

<img src=`https://www.cryptocompare.com/{this.state.cryImage}` />

In this.state.cryImage, I only get the second half of the link (I'm pulling data from an API) so for example it would be something like:

media/19633/btc.png

Am I concatenating incorrectly or is this just not possible?

like image 615
anbhd Avatar asked Dec 13 '22 18:12

anbhd


1 Answers

You've missed $ sign and brackets for attribute

<img src={`https://www.cryptocompare.com/${this.state.cryImage}`} />
like image 115
Ihor Lavs Avatar answered Dec 18 '22 00:12

Ihor Lavs