Skip to content

Instantly share code, notes, and snippets.

@shakdaniel
Last active February 5, 2020 14:23
Show Gist options
  • Save shakdaniel/2019f54a5dd88451457c64e7f0302c99 to your computer and use it in GitHub Desktop.
Save shakdaniel/2019f54a5dd88451457c64e7f0302c99 to your computer and use it in GitHub Desktop.
[Markdown to jsx] impliment .md file into react compnent. #React
// 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