title: How to use local storage to store data from an API
body: <p>I want to get data from an API only once in a while(say, once every hour) and store it locally and use that data on my website without having to call that api again and again everytime the person refreshes the browser. How can we achieve this. Can we use localStorage for that purpose. If yes then how?</p>
  
  <p>I am using this:</p>
  
  <pre><code>fetch("https://coronavirus-tracker-api.herokuapp.com/deaths")
  .then(res=&gt;{
    return res.json();
  })
  .then(data=&gt;{
    localStorage.setItem("data",JSON.stringify(data));
    console.log(localStorage.getItem("data"))
  })
  </code></pre>
  
  <p>but this would call the api everytime the page reloads. But instead of calling to the api again and again I want to store data in the localstorage and get data to view on the page from there.</p>