Im trying to get html from another file, set it to state and render to my web page using react. But when i render the result on the page it keeps on coming as jumble HTML (the html is showing as plain words).
After testing for hours it looks like the response comes in as a string, that's why its printing words, but how do i prevent that.
<script type="text/babel">
class myClass extends React.Component {
constructor() {
super();
this.state = {resultState: ""};
};
componentDidMount() {
axios.post(`mysite.com/page.php`) //in this file it says <h1>green</h1>
.then(res => {
console.log(res.data);
this.setState({ resultState: res.data });
})
}
changeColor = () => {
this.setState({resultState: <h1>blue</h1>});
};
render() {
return (
<div>
{this.state.resultState}
</div>
)
}
}
ReactDOM.render(<myClass />, document.getElementById('mydiv'))
</script>
It keeps on returning <h1>green</h1> instead of a large word "green".
In the console it does show as html (the code is indented like the file)