import React from 'react';
import marked from 'marked';
export class Markdown extends React.Component {
constructor(){
super();
this.state = {
value: '# Sample Markdown Heading'
}
this.handleChange = this.handleChange.bind(this);
}
getMarkup(){
var md = marked(this.state.value);
return {__html: md};
}
handleChange(e){
this.setState({
value: e.target.value
})
}
render(){
return (
<div className='row'>
<div className="input-div col-md-6">
<h2>Input</h2>
<textarea onChange={this.handleChange} value={this.state.value}>
</textarea>
</div>
<div className="result-div col-md-6">
<h2>Result</h2>
<textarea readOnly={true} value={this.state.value}>
<div dangerouslySetInnerHTML={this.getMarkup}></div>
</textarea>
</div>
</div>
);
}
}
When I try to change the input I get the same output as the input. I imported and installed the marked library but when i use it in the getMarkup() function it doesen’t appear to work. Please help the above is my code.