title: clearTimeout in Redux action file
body: <p>I'm trying to implement auto-refresh (fetch data from API again) functionality in redux app. I was wandering if it is ok to use global variable in <code>../action.js</code> to use clearTimeout in other function - for stop auto-refresh after changing page or fulfill any other condition.
  Is it ok or should I take different approach?</p>
  
  <p><strong>../action.js</strong></p>
  
  <pre><code>import fetchWeather from '../../shared/fetchWeather';
  import * as actionTypes from '../actions/actionTypes';
  
  let refreshTimeout = null;
  
  
  export const refresh = (endpoint, queryParams) =&gt; {
    return dispatch =&gt; {
      refreshTimeout = setTimeout(() =&gt; {
        dispatch(initWeather(endpoint, queryParams));
      }, 1000)  
    }
  }
  
  export const initWeather = (endpoint, queryParams) =&gt; {
    return dispatch =&gt; {
      fetchWeather(endpoint, queryParams)
        .then(response =&gt; {
          dispatch(setWeather(response.data));
          dispatch(refresh(endpoint, queryParams))
        })
        .catch(error =&gt; {
          dispatch(fetchWeatherFailed(error.message))
        })
    }
  }
  
  export const initForecast = (endpoint, queryParams) =&gt; {
    clearTimeout(refreshTimeout); // clearTimeout to stop refreshing (re-fetching data)
    return dispatch =&gt; {
      fetchWeather(endpoint, queryParams)
        .then(response =&gt; {
          dispatch(setForecast(response.data))
        })
        .catch(error =&gt; {
          dispatch(fetchForecastFailed(error.message))
        })
    }
  }
  </code></pre>
  
  <p>.
  .
  .</p>