所以我有一个组件,当单击按钮时,它将在父组件中调用。
我添加了一个条件,即只能运行一次ComponentDidUpdate
。但是它仍然调用API 5次。
这是我的代码。
componentDidUpdate(prevProps) {
var seqNum = this.props.seqNum;
//Condition to control multiple requests
if(prevProps.seqNum !== seqNum) {
this.getCheckList();
}
getCheckList() {
var seqNum = this.props.seqNum;
var vehicleId = this.props.vehicleId;
//Get EventDetails
var urlLink = "getEvent?vehicleId="+vehicleId+"&seqNum="+seqNum;
axios.get(urlLink)
.then(res => {
this.setState({eventData: res.data})
console.log(res.data+ "This fil")
})
}
为什么会这样?有任何想法吗? 或者,如果您需要任何其他信息,请问我。我将在这里更新代码。