title: How can I cancel the setTimeout time in react
body: <p>I have created an application in which when a button is pressed the clock time starts. If nothing is done after 23 seconds (23000) is set to 0 and the state is changed (this.state.user) .This is correct.</p>
  
  <p>If you click on the element again, I need the 23 seconds (23000) to be zeroed and the Timeout cleaned. Because if there is still some time left in the timeout, the item closes automatically.</p>
  
  <p>I tried "clearTimeout (this.change);
  clearInterval (this.change); "but it doesn't work, I don't know how to cancel this time.</p>
  
  <pre><code>class Header extends Component {
      constructor(props) {
          super(props);
  
          this.change = null;
  
          this.state = {
              usuario: true,
              timeElapsed: 0,
              adminOrWrap: true,
          };
  
          ["descansoAdminWrap", "otrosDescansos",].forEach((method) =&gt; {
              this[method] = this[method].bind(this);
          });
      }
  
     componentDidUpdate(prevProps, prevState) {
          if (prevProps.notInCall === false &amp;&amp; this.props.notInCall &amp;&amp; this.state.usuario === true) {
              this.descansoAdminWrap(prevProps, prevState);
         }
     }
  
      descansoAdminWrap(prevProps){
          var usuarioAdminOrWrapFalse=  this.state.usuario &amp;&amp; this.props.adminOrWrap === false;
          var notInCallFalseUsuario= this.props.notInCall === false &amp;&amp; this.state.usuario
          //mostrar y ocultar el descanso de 'tiempo administrativo' y 'wrap time'
          if(this.state.usuario &amp;&amp; this.props.notInCall){
              this.setState({
                  usuario: false,
                  timeElapsed: 0,
              });
              clearTimeout(this.change);
              clearInterval(this.change);
              if(prevProps.notInCall === false){
                  this.handleAdminOrWrap(false)
                  this.setState({
                      usuario: false,
                      timeElapsed: 0,
                  });
                  this.change = setTimeout(() =&gt; {
                      this.setState({
                          usuario: true,
                          notInCall: true,
                      });
                      this.handleAdminOrWrap(true)
                  }, 23000)
              }
          }
      }
  </code></pre>