Reputation: 5150
I want to use the prop as part of the file name as part of the src for an image but I'm clearly doing something wrong.
I am passing on the name as string, and then using the name to form the url for the image. I've tried using the back tick "`" but that doesn't work either.
import React from 'react';
type AppProps = {
name: string
description: string
}
const PartnerIcon: React.FC<AppProps> = ({name, description}) => {
return (
<div className="partner-icon">
<img src="../images/{name}.svg" className="span-row-2"></img>
<b>{name}</b>
<p>{description}</p>
</div>
);
}
export default PartnerIcon;
Upvotes: 2
Views: 118
Reputation: 1006
You can use string interpolation like that :
<img src={`../images/${name}.svg`} className="span-row-2"></img>
Upvotes: 1
Reputation: 5508
Try this:
<img src={`../images/${name}.svg`} className="span-row-2"></img>
Upvotes: 2
Reputation: 2595
You can use string interpolation.
<img src={`../images/${name}.svg`} className="span-row-2"></img>
Upvotes: 2