im newbie in React and trying to make a headless worpdpress aplication.
when i fetch a post i get only the first value.
I fetch the post and save it in the state
componentDidMount() {
this.setState({ loading: true }, () => {
axios.get('http://localhost/wpprojekte/ebike/wp-json/wp/v2/posts/426')
.then(res => {
this.setState({ loading: false, error: 'no error', post: res.data })
}).catch(error => {
console.log(error);
});
});}
I have now the post in my state which looks like
constructor(props) {
super(props);
this.state = {
loading: false,
error: 'error',
post: {},
}}
when i render the Component, i can get only the first value from the post.
for example this.state.post.date
when i try to get this.state.post.title.rendered
Uncaught TypeError: Cannot read properties of undefined (reading 'rendered')
here is The render function
render() {
return (
<div>
{<div dangerouslySetInnerHTML={{ __html: this.state.post.title.rendered }} />}
</div>
)}
I dont understand why it is getting only the first value.