【发布时间】:2018-05-01 01:48:04
【问题描述】:
在 ReactJs 的一个函数中重新渲染相同的组件。我正在添加评论,然后我想重新渲染相同的组件。有人可以帮忙吗?
commentPost() {...
axios.defaults.headers.common['Authorization'] = getToken;
axios.post(apiBaseUrl+'v1/comments/post-comment',input)
.then(function (response) {
console.log("Comment Post",response);
//here I want to rerender this component itself
})
.catch(function (error) {
console.log(error);
});...
【问题讨论】:
-
React 在其状态发生变化时触发组件重新渲染。您需要更新组件的状态,因此值得重新渲染它以显示更新的状态。
-
您需要设置状态以使响应重新渲染。
标签: javascript reactjs rerender react-lifecycle