title: How to cleanup setTimeout/setInterval in event handler in React?
body: <p>How can I clean up function like <code>setTimeout</code> or <code>setInterval</code> in event handler in React? Or is this unnecessary to do so?</p>
  <pre class="lang-js prettyprint-override"><code>import React from 'react'
  
  function App(){
    return (
      &lt;button onClick={() =&gt; {
        setTimeout(() =&gt; {
          console.log('you have clicked me')
          //How to clean this up?
        }, 500)
      }}&gt;Click me&lt;/button&gt;
    )
  }
  
  export default App
  </code></pre>