0

I want to use js syntax to have diffrent URL for each image. Robohash website give us random robot image if we use diffrent URL ending, in that way i want to do below, but looks like ${props.id} is not treated as syntax but just as a part of URL, so im gets the same image for all.

<img alt='robots' src={"https://robohash.org/${props.id}"} />
AndreGTH
  • 31
  • 3
  • To use a template string you have to use back ticks not double quotes. the other option would be to append the value to the end of the string like src={"https://robohash.org/" + props.id}. – osekmedia Jul 29 '20 at 08:24

2 Answers2

0

You should use template string using backticks:

<img alt='robots' src={`https://robohash.org/${props.id}`} />
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
Joshua
  • 3,055
  • 3
  • 22
  • 37
0
<img alt='robots' src={`https://robohash.org/${props.id}`} />
susanta96
  • 89
  • 5
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Dima Kozhevin Jul 29 '20 at 10:32