I'm using react helmet server side and I am trying to get the meta tags from a Wordpress API, like post excerpt, image, title and so on. I'm using axios to make a request to the WP API.
React Helmet is working, but everytime I try to get the tags from the WP API via state it toggles me a re-render and does not updates it on Open Graph Object Debugger.
Here's the code i'm using:
constructor(props) {
this.state = { posts : [] };
}
_getPosts(){
axios.get( URL.path + URL.posts + '?slug=' + this.props.match.params.id )
.then( res => {
this.setState({ posts: res.data });
});
}
componentWillMount(){
this._getPosts();
}
render(){
return(
<Helmet>
<meta name="description" content={this.state.posts.title} />
<meta property="og:image" content){this.state.posts.featured_image} />
</Helmet>
);
}