title: Run function only once in React?
body: <p>I have a react redux project.  I have the below method:</p>
  
  <pre><code>const UmvValidator = (actions) =&gt; {
      const expiryTime = localStorage.getItem('expiryTime')
      const currentTime = moment().valueOf()
      if (expiryTime) {
          if (expiryTime.valueOf() &gt; currentTime) {
              localStorage.clear('expiryTime')
  
          }
      } else {
          actions.directToLogin()
      }
  }
  </code></pre>
  
  <p>actions.directToLogin() looks like this:</p>
  
  <pre><code>export function directToLogin() {
      return function (dispatch) {
          dispatch(push('/'));
      }
  }
  </code></pre>
  
  <p>I want to run this method once, when my component first renders like so:</p>
  
  <pre><code>componentWillMount() {
          const { actions } = this.props
           umvValidator(actions)
      }
  </code></pre>
  
  <p>The idea is that if the expiry time is later than the current time, the user will be redirected to the home page.  This sort of works - the user is directed from one page to the home page.  However the home page continues to flicker between the home page and the original page because the umvValidator keeps getting called!</p>
  
  <p>I have no idea to solve this, thanks for any help!</p>