title: How to auto refresh data in real time, react?
body: <p>making a basic spotify app using React for the first time. currenty the "Now playing" feature is using a button to display what is being played by the user. How can I change this command so it does it in real time as apposed to a click of a button?</p>
  
  <pre><code>&lt;button onClick={() =&gt; this.getNowPlaying()}&gt;
     Check Now Playing
   &lt;/button&gt;
  </code></pre>
  
  <p>Any help would be great :)
  Full code example is below</p>
  
  <pre><code>import React, { Component } from 'react';
  import './App.css';
  import Spotify from 'spotify-web-api-js';
  
  const spotifyWebApi = new Spotify();
  
  class App extends Component {
    constructor(){
      super();
      const params = this.getHashParams();
      this.state ={
        loggedIn: params.access_token ? true : false,
        nowPlaying: {
          name: 'Not Checked',
          image: ''
         }
       }
      if (params.access_token){
        spotifyWebApi.setAccessToken(params.access_token)
      }
    }
    getHashParams() {
      var hashParams = {};
      var e, r = /([^&amp;;=]+)=?([^&amp;;]*)/g,
          q = window.location.hash.substring(1);
      while ( e = r.exec(q)) {
         hashParams[e[1]] = decodeURIComponent(e[2]);
      }
      return hashParams;
    }
  
    getNowPlaying(){
      spotifyWebApi.getMyCurrentPlaybackState()
        .then((response) =&gt; {
          this.setState({
            nowPlaying: {
              name: response.item.name,
              image: response.item.album.images[1].url
            }
          })
        }
      )
    }
  
    render() {
      return (
      &lt;div className="App"&gt;
        &lt;a href='http://localhost:8888'&gt;
        &lt;button&gt;Login But With Spotify &lt;/button&gt;
        &lt;/a&gt;
        &lt;div&gt; Now Playing: { this.state.nowPlaying.name} &lt;/div&gt;
      &lt;div&gt;
      &lt;img src={ this.state.nowPlaying.image} style={{ width: 100}}/&gt;
      &lt;/div&gt;
      &lt;button onClick={() =&gt; this.getNowPlaying()}&gt;
        Check Now Playing
      &lt;/button&gt;
      &lt;/div&gt;
  </code></pre>