JScript Refreshing Fetch Example

We can use setInterval function to refresh our fetched values automatically.

setInterval(function(){ }, 1000); // Runs our function repetitively every 1 seconds…

   componentDidMount() {
    setInterval(() => {
      return fetch('https://YOUR_API_URL')
        .then((response) => response.json())
        .then((responseJson) => {
          this.setState({
            dataSource: responseJson,
          }, function () {
          });
        })
        .catch((error) => {
          console.error(error);
        });
    }, 1000);
  }