I am developing a markdown-to-jsx img
override and depending on if an image is relative (
) or a hyperlink (
), I wish to handle things differently.
The following code works fine, but I want to make sure it is future-proof. I have stopped using requires a while ago in favor of imports but imports cannot be dynamic.
interface ImageProps {
alt: string
src: string
}
const Image = function(props: ImageProps) {
let src: string
if (props.src.match(/^http(s)?:\/\//)) {
src = props.src
} else {
src = require(props.src)
}
return <img alt={props.alt} src={src} />
}