access to the endpoints wp api rest title post rendered inreact app

admin

Administrator
Staff member
I cracking my head against the wall, I'm developing a React App with wordpress as an API (wp rest API). everything is working well, I'm fetching and rendering all the post but when I go to the single post I can't fetch and render the title and content because it's said {rendered: "dwdwdf"} and I do the {post.title.rendered} as I do in the postlist component to get the title and works but in the single post doesn't.

To make it more clear here is the code:

Code:
const id = this.props.match.params.id;
let postUrl = `http://thesite.com/wp-json/wp/v2/posts/${id}`;
fetch(postUrl)
  .then(data => data.json())
  .then(data => {
      this.setState({
         item: data
      })
  })

when I console the this.state.item.title it shows me this:

Code:
{rendered: "dwdwdf"}
rendered: "dwdwdf"
__proto__: Object

it should be render as I do in my postlist component, like this {this.state.item.title.rendered} and done ! but not, it gave me this error:

TypeError: Cannot read property 'rendered' of undefined

I checked the api rest wp documentation and a lot of blogs and stackoverflow but I can't find anything that helps me.

if someone can guide me, thanks.