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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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