title: is there a way to pass variable inside of a function outside in react
body: <p>I am new to react, and I am trying to make a simple countdown app. but in react, I don't know how to give a global variable for all the functions can get assess to it. Please take a look at my code, is there anyway I can make the pause and the continue buttons work? In plain javascript I can set timer as a global variable and get access to it from another function, by that, I can call clearInterval on timer when I want, but in react I don't know how to call clearInterval for timer to pause begin function since it is restricted in the begin function block.</p>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  
  class Countdown extends React.Component{
      render(){
          return(
              &lt;div&gt;
                  &lt;button onClick={()=&gt;begin()}&gt;start&lt;/button&gt;
                  &lt;button&gt;pause&lt;/button&gt;
                  &lt;button&gt;continue&lt;/button&gt;
              &lt;/div&gt;
          );
      }
  };
  
  const begin=(props)=&gt;{
      let count = 10;
      const timer = setInterval(countdown,1000);
      function countdown(){
          count=count-1
          if (count&lt;0){
              clearInterval(timer);
              return; 
          }
          console.log(count)
      }
  }
  
  ReactDOM.render(&lt;Countdown/&gt;, document.getElementById('app'));
  </code></pre>