I'm using react js 15.4.2. I have html data stored as string like "<p>Hello..</p>". I can not append them to the DOM.
...
componentDidMount(){
let obj = dataFromDB.map((data)=>{
return(
<div>
{data.strHtml}
</div>
)
})
this.setState({storedObj: obj})
}
render(){
return(
<div>
{this.state.storedObj}
</div>
)
}
...
Do you have any suggestions to append the html objects to the DOM properly ?
you could also look into react-html-parser module for parsing html before rendering to the DOM it's pretty easy to use.
import Parser from 'html-react-parser';
class Example extends React.Component {
render() {
return (
<div>
{Parser(this.state.dataStored)}
</div>
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With