Use setInterval instead of setTimeout in CaptchaField
This commit is contained in:
parent
642282f049
commit
ffb1804c59
1 changed files with 9 additions and 8 deletions
|
@ -28,18 +28,19 @@ class CaptchaField extends React.Component {
|
|||
|
||||
state = {
|
||||
captcha: ImmutableMap(),
|
||||
refresh: undefined,
|
||||
}
|
||||
|
||||
setRefreshTimeout = () => {
|
||||
startRefresh = () => {
|
||||
const { refreshInterval } = this.props;
|
||||
if (refreshInterval) {
|
||||
const refreshTimeout = setTimeout(this.fetchCaptcha, refreshInterval);
|
||||
this.setState({ refreshTimeout });
|
||||
}
|
||||
const refresh = setInterval(this.fetchCaptcha, refreshInterval);
|
||||
this.setState({ refresh });
|
||||
};
|
||||
}
|
||||
|
||||
clearRefreshTimeout = () => {
|
||||
clearTimeout(this.state.refreshTimeout);
|
||||
endRefresh = () => {
|
||||
clearInterval(this.state.refresh);
|
||||
}
|
||||
|
||||
fetchCaptcha = () => {
|
||||
|
@ -51,15 +52,15 @@ class CaptchaField extends React.Component {
|
|||
}).catch(error => {
|
||||
onFetchFail(error);
|
||||
});
|
||||
this.setRefreshTimeout(); // Refresh periodically
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.fetchCaptcha();
|
||||
this.startRefresh(); // Refresh periodically
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.clearRefreshTimeout();
|
||||
this.endRefresh();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
Loading…
Reference in a new issue