title: React Native - use a state variable in a static function
body: <p>I'm new to React-Native, i have a problem creating my app.
  Basically, i have a main application that do things, one of those is setting a Date variable in state called: sleepTime.
  Now i've created a clock that works perfectly and every seconds is updated.
  My problem now is to create a function into my main application that compare the actual date (given from the clock) with the date saved before.
  The problem is that i've used a static function wich is called on every tick in the clock class, this function (compareTime()) is in the main class and obviusly i get the "undefined is not an object" when I call it.
  What i can't figure out is how to link the call made by clock with the date that i've saved before.</p>
  
  <p>This is the static function:  </p>
  
  <pre><code>static compareTime(){
    const sleepTime = this.state.sleepTime;
        if(new Date().toLocaleString() == sleepTime){
          this.stopTimer();
        }
   }
  </code></pre>
  
  <p>Clock class:</p>
  
  <pre><code>class Clock extends React.Component {
            constructor(props) {
              super(props);
              this.state = {
                time: new Date().toLocaleString()
              };
            }
            componentDidMount() {
              this.intervalID = setInterval(
                () =&gt; this.tick(),
                1000
              );
            }
            componentWillUnmount() {
              clearInterval(this.intervalID);
            }
            tick() {
              this.setState({
                time: new Date().toLocaleString()
              });
              MainPage.compareTime();
            }
  
            render() {
              return (
                &lt;Text style={styles.greeting}&gt;
                  The time is: {this.state.time}
                &lt;/Text&gt;
              );
            }
          }
  </code></pre>
  
  <p>And the return of the main render wich is the only thing that links main and clock:</p>
  
  <pre><code> return (
        &lt;View style={styles.container}&gt;
          &lt;Clock /&gt;
          &lt;Text style={styles.greeting}&gt;
              Sleep time: {sleepTime}.
          &lt;/Text&gt;
        &lt;/View&gt;
   )
  </code></pre>