react corresponds to two asynchronous requests in the same component, which indicates that state maintenance is cumbersome
here is my code
componentWillReceiveProps(nextProps){
const {result1, result2} = nextProps;
if(result1 === "success"){
console.log(1)
}
if(result2 === "success"){
console.log(2)
}
}
when request 2 succeeds, the status of request 1 is still success and they will execute it all, but I just need them to execute it once each. My own solution is to compare the props value with the current value, but the tedious result is as follows:
componentWillReceiveProps(nextProps){
const {result1, result2} = nextProps;
const {result1: originalValue1, result2: originalValue2} = this.props;
if(result1 === "success" && result1 !== originalValue1 ){
console.log(1)
}
if(result2 === "success" && result2 !== originalValue2){
console.log(2)
}
}
-another type of sharp-sharp-sharp is the reset result value after finishing, but it will be re-render. I hope you can give better suggestions, thank you!