I want to generate dynamic meta tags in my React app. I'm using Helmet and have a problem because it is empty after calling Helmet.renderStatic(). My index.js file:
const store = createStore(rootReducer);
ReactDOM.render(<Provider store={store}><App /></Provider>,
document.getElementById('root') as HTMLElement
);
const helmet = Helmet.renderStatic();
console.log('meta', helmet.meta.toString());
registerServiceWorker();
and my component looks like that:
public render() {
const { article } = this.state;
return (
<div className="article-published">
<Helmet>
<meta charSet="utf-8" />
<meta property="og:title" content={article.title} />
</Helmet>
The problem is that I'm calling API to get article, so when I get a helmet in my index.js article is not there yet, so my helmet.meta has no content.
How can I make it wait for the article to be received from API to use it in the title?