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 = {
|
state = {
|
||||||
captcha: ImmutableMap(),
|
captcha: ImmutableMap(),
|
||||||
|
refresh: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
setRefreshTimeout = () => {
|
startRefresh = () => {
|
||||||
const { refreshInterval } = this.props;
|
const { refreshInterval } = this.props;
|
||||||
if (refreshInterval) {
|
if (refreshInterval) {
|
||||||
const refreshTimeout = setTimeout(this.fetchCaptcha, refreshInterval);
|
const refresh = setInterval(this.fetchCaptcha, refreshInterval);
|
||||||
this.setState({ refreshTimeout });
|
this.setState({ refresh });
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
clearRefreshTimeout = () => {
|
endRefresh = () => {
|
||||||
clearTimeout(this.state.refreshTimeout);
|
clearInterval(this.state.refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchCaptcha = () => {
|
fetchCaptcha = () => {
|
||||||
|
@ -51,15 +52,15 @@ class CaptchaField extends React.Component {
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
onFetchFail(error);
|
onFetchFail(error);
|
||||||
});
|
});
|
||||||
this.setRefreshTimeout(); // Refresh periodically
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.fetchCaptcha();
|
this.fetchCaptcha();
|
||||||
|
this.startRefresh(); // Refresh periodically
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.clearRefreshTimeout();
|
this.endRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
Loading…
Reference in a new issue