title: How to clear setTimer in another function
body: <p>A component is calling a function in another file, a setTimer is use to update a variable:</p>
  
  <p>timer.js</p>
  
  <pre><code>const timer = () =&gt; {
    this.timeout = setTimeout(() =&gt; {
      pressTwice = false;
    }, duration);
  };
  </code></pre>
  
  <p>timerUI.js</p>
  
  <pre><code>componentDidMount() {
      timer();
    }
  
    componentWillUnmount() {
      clearTimeout(this.timeout);// how to clean the this.timeout?
    }
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>Can't perform a React state update on an unmouted component.
  </code></pre>