fix: clean timeout when componentWillUnmount in PaymentResult page (#1962)

This commit is contained in:
907997375
2023-06-13 02:00:52 +08:00
committed by GitHub
parent 451fc9034f
commit 2a8001f490

View File

@ -25,6 +25,7 @@ class PaymentResultPage extends React.Component {
classes: props, classes: props,
paymentName: props.match.params.paymentName, paymentName: props.match.params.paymentName,
payment: null, payment: null,
timeout: null,
}; };
} }
@ -32,6 +33,12 @@ class PaymentResultPage extends React.Component {
this.getPayment(); this.getPayment();
} }
componentWillUnmount() {
if (this.state.timeout !== null) {
clearTimeout(this.state.timeout);
}
}
getPayment() { getPayment() {
PaymentBackend.getPayment("admin", this.state.paymentName) PaymentBackend.getPayment("admin", this.state.paymentName)
.then((payment) => { .then((payment) => {
@ -40,7 +47,7 @@ class PaymentResultPage extends React.Component {
}); });
if (payment.state === "Created") { if (payment.state === "Created") {
setTimeout(() => this.getPayment(), 1000); this.setState({timeout: setTimeout(() => this.getPayment(), 1000)});
} }
}); });
} }