title: How to stop timer in react native
body: <pre><code>import React, { Component } from 'react';
  import { Text, View, TextInput, Button, Alert, Switch } from 'react-native';
  import TimerMixin from 'react-timer-mixin';
  
  export default class home extends React.Component {
    constructor(props) {
      super(props)
      this.state = { switchstate: false, timer: null };
      var timer = setInterval(this.tick, 1000);
      this.setState({ timer });
    }
    tick = async () =&gt; {
      return await console.log('asdas', 'iam printing')
    }
  
    toogleswitchstate = () =&gt; {
      if (this.state.switchstate == false) {
        this.setState({ switchstate: true })
      } else if (this.state.switchstate == true) {
        this.setState({ switchstate: false })
        clearInterval(this.timer);
        //geolocation.stopObserving();
      }
      console.log(this.state.switchstate)
    }
  
    render() {
      return (
        &lt;View style={{ flex: 1, flexDirection: 'column', justifyContent: 'space-evenly', alignItems: 'center', backgroundColor: datum.secondaryColor }}&gt;
          &lt;Button
            title={String(this.state.switchstate)}
            onPress={() =&gt; this.toogleswitchstate()}
          /&gt;
        &lt;/View&gt;
      );
    }
  }
  </code></pre>
  
  <p>I designed this code to trigger the timer when this component is executed, but I don't know  how to stop the timer, i have cropped the code for stack overflow restriction </p>
  
  <p><strong>Expected behaviour:</strong>
  the toogleswitchstate function will stop the timer </p>
  
  <p><strong>What actually happened:</strong>
  Throws me a weird error</p>