1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-11 12:34:20 +01:00
ipfs-boards/webapp/components/markdown.jsx

26 lines
687 B
React
Raw Normal View History

2015-11-20 20:21:54 +01:00
var React = require('react')
module.exports = React.createClass({
getInitialState: function(){
return { lib: false }
},
componentDidMount: function(){
require.ensure(['react-markdown'],_ => {
if(this.isMounted()) this.setState({ MarkdownLib: require('react-markdown') })
})
},
2015-11-20 20:21:54 +01:00
renderIfApplicable: function(){
if(this.props.source){
if(this.state.MarkdownLib){
var MarkdownLib = this.state.MarkdownLib
return <MarkdownLib source={this.props.source} skipHtml={true} />
} else {
return <p>{this.props.source}</p>
}
} else return <p>...</p>
2015-11-20 20:21:54 +01:00
},
render: function(){
return this.renderIfApplicable()
}
})