componentWillReceiveProps(nextProps) {
if(nextProps.isOpen){
const { selectedItemId} = this.props;
//ajax
}
}
我有一个需要调用API的模态组件,我这样做,isOpen是打开和关闭模式的标志,但是通过这种方法,我得到了无限的调用。
答案 0 :(得分:0)
在请求/呈现
时,只需使用标记就不会一直请求componentWillReceiveProps(nextProps) {
if(nextProps.isOpen && !this.requesting){
const { selectedItemId } = this.props;
this.requesting = true;
//ajax
ajax.then( () => {
this.requesting = false;
})
}
}