Reputation: 45
i cannot get my image in the markdown file to render. I am requiring the markdown file in a react component, but the image in the md file is not rendering. absolute paths to online images are working, but relative paths are not.
useEffect(() => { fetch(require(`../../../static/markdowns/${category.file}`)).then(r => r.text()).then(text => { setMarkDown(text) }) }, [])
<ReactMarkdown escapeHtml={false} source={markDown}/>
<img src='https://picsum.photos/200/300'></img>
<img src="./personwithchart.png" alt="Text">


the picsums work but ./ or ../../../static/markdowns/file do not.
thanks
Upvotes: 1
Views: 3606
Reputation: 707
If you're using something like Create React App and the image is in your public/
folder, you should be able to do <img src="/personwithchart.png" alt="Text">
. The public/
directory should be accessible on your URL's root, therefore you don't need the ./
UNIX convention.
Upvotes: 6