import { Helmet } from "react-helmet";
class Article extends Component {
state = {
articleContent: null,
};
componentDidMount() {
this._getArticleDetail();
}
_getArticleDetail() {
SingleArticle.getSingleArticle(this.props.match.params.id)
.then(response => {
this.setState({
articleContent: response.data.article[0].content,
});
}
render() {
let pageUrl = window.location.href;
let prerenderHeader = "Location:" + pageUrl;
return(
<Helmet>
<title>{this.state.articleContent && this.state.articleContent.title}</title>
<meta name="description" content={this.state.articleContent && this.state.articleContent.description} />
<meta name="keywords" content=this.state.articleContent && this.state.articleContent.keywords/>
</Helmet>
)
}
我的问题是,当安装组件时,文章标题,描述为null。只有在异步api调用之后,我才能获取所需的信息。在这种情况下,元标记会更新吗?