I am new to React so I am just trying to pull data from my wordpress website API. I am getting a generic blog post which will display this.state.post.link fine but not any of the rendered data.
import React from 'react'
export default React.createClass({
getInitialState: function () {
return {
post: {},
}
},
componentDidMount: function () {
var _this = this;
$.get('http://somewebsite.net/wp-json/wp/v2/posts/1258', function(result) {
_this.setState({
post: result
});
});
},
render() {
console.log(this.state.post);
return <div className="single-post">
<h1>{this.state.post.link}</h1>
<h1>{this.state.post.title.rendered}</h1>
</div>
}
});
I get this error from adding post.title.rendered.
bundle.js:51835 Uncaught TypeError: Cannot read property 'rendered' of undefined
This is what shows with the code console.log(this.state.post.title);
Object {rendered: "Example post"}
So why can I console.log this.state.post.title and it shows the object with rendered in but then if I try and display that it will say title is undefined?