我应该把我的逻辑放在哪里,这些逻辑应该在挂载之后运行,也应该在更新组件之后运行?
例如,如果我想根据从redux和/或父组件接收到的参数调用一些api thunk。
现在我正在使用这种方法,但是它是正确的还是我遗漏了什么?
componentDidMount(){
this.componentDidUpdate()
}
componentDidUpdate(){
// the logic (ex: redux-thunk api call)
}
发布于 2018-04-10 14:51:36
我不认为你正在做的事情会有副作用,但我认为你不应该像那样调用react本机函数。
我会这样做:
componentDidMount() {
this._randomFunction();
}
componentDidUpdate() {
this._randomFunction();
}
_randomFunction(){
// your logic
}
https://stackoverflow.com/questions/49756661
复制相似问题