Use setInterval instead of setTimeout in CaptchaField

stable/1.0.x
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 = { 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() {