title: Polling API every x seconds with react
body: <p>I have to monitoring some data update info on the screen each one or two seconds.
  The way I figured that was using this implementation:</p>
  <pre class="lang-js prettyprint-override"><code>    componentDidMount() {
          this.timer = setInterval(()=&gt; this.getItems(), 1000);
        }
      
        componentWillUnmount() {
          this.timer = null;
        }
      
        getItems() {
          fetch(this.getEndpoint('api url endpoint'))
              .then(result =&gt; result.json())
              .then(result =&gt; this.setState({ items: result }));
        }
  </code></pre>
  <p>Is this the correct approach?</p>