title: How to clear a settimeout in react
body: <p>On each question component, I am trying to clear the time out. So on <code>componentWillMount()</code> I will start the timer and then on <code>componentDidUpdate()</code> I will clear the timeout. The timer does not seem to be working.After the timer expires I will push the user back to the home page. Any idea why the using <code>clearTimeout()</code> isnt working?</p>
  
  <pre><code>class Questions extends Component { 
      constructor(props){
          super(props);
          this.state ={
              error: false,
              position: null,
              redirect: false
          } 
          this.error = this.error.bind(this);   
          this.errorFalse = this.errorFalse.bind(this); 
          this.timer = this.timer.bind(this); 
      }
      timer=()=&gt;{
          setTimeout(() =&gt; { 
              console.log('this ran') 
              this.setState({
                  redirect: true
              })
  
      }, 5000)
      }
      componentWillMount(){
          this.setState({
              error: false
          })
          this.timer();
  
      }
      componentDidUpdate(prevProps, prevState, snapshot, timer){
          console.log('updated')
          clearTimeout(this.timer);
      }
  </code></pre>