Created
March 8, 2022 00:29
-
-
Save ljaviertovar/1c940268abab39544033474df14b200d to your computer and use it in GitHub Desktop.
Component to render a markdown file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react" | |
import Markdown from "markdown-to-jsx" | |
import Code from "./Code" | |
import cover from '../assets/img/cover.jpeg' | |
import '../styles/Post.css' | |
const Post = () => { | |
const [postContent, setPostcontent] = useState('') | |
const [isDark, setIsDark] = useState(true) | |
useEffect(() => { | |
import('../tutorials/tutorial1.md') | |
.then(res => | |
fetch(res.default) | |
.then(response => response.text()) | |
.then(response => setPostcontent(response)) | |
.catch(err => console.log(err)) | |
) | |
}, []) | |
return ( | |
<div className="article-wrapper"> | |
<article> | |
<header> | |
<div className="article__cover"> | |
<img | |
src={cover} | |
alt="my-cover" | |
/> | |
</div> | |
</header> | |
<main> | |
<Markdown | |
options={{ | |
overrides: { | |
Code: { | |
component: Code, | |
props: { | |
isDark, | |
setIsDark | |
} | |
} | |
} | |
}} | |
> | |
{postContent} | |
</Markdown> | |
</main> | |
</article> | |
</div> | |
) | |
} | |
export default Post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment