Use setInterval instead of setTimeout in CaptchaField

merge-requests/1/head
Alex Gleason 2020-04-28 12:09:37 -05:00
rodzic 642282f049
commit ffb1804c59
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 9 dodań i 8 usunięć

Wyświetl plik

@ -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() {