I'm new to React and TypeScript. I cannot find a solution for this on Google.
I have a component that outputs an image. I want to wrap that image in an <a> tag if there is a given URL prop. I am unsure how to write the logic simply enough.
From looking online I have written the following:
const imageBlock = ({
imageSrc,
imageAlt,
imageTitle,
imageLink,
}: imageBlockProps) => {
return (
imageLink && (
<a href={imageLink}>
)
<img src={imageSrc} alt={imageAlt} title={imageTitle} />
imageLink && (
</a>
)
)
};
But I cannot get it to work.
Would anyone know the best way to do it?
<img>