Last active
February 5, 2020 14:23
-
-
Save shakdaniel/2019f54a5dd88451457c64e7f0302c99 to your computer and use it in GitHub Desktop.
[Markdown to jsx] impliment .md file into react compnent. #React
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
// https://probablyup.com/markdown-to-jsx/ | |
// npm install -D markdown-to-jsx | |
// yarn add -D markdown-to-jsx | |
import React, { Component } from 'react' | |
import Markdown from 'markdown-to-jsx'; | |
import README from './README.md' | |
class PageComponent extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { md: "" } | |
} | |
componentWillMount() { | |
fetch(README) | |
.then((res) => res.text()) | |
.then((md) => { | |
this.setState({ md }) | |
}) | |
} | |
render() { | |
let { md } = this.state | |
return ( | |
<div className="post"> | |
<Markdown children={md}/> | |
</div> | |
) | |
} | |
} | |
export default PageComponent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment