0

I am able to retrieve data from my api and store in localStorage and display on my views. But when there is change, how can my localStorage update itself? I understand it is a bad practice to call API's everytime you land on a page. I store data in a localStorage but my issue is, when there is a change in the data in the server side, how can i detect it i am using localStorage to display data in my views.

How can i update my localStorage anytime there is a change or update in the API / server side ?

RoboPHP
  • 357
  • 1
  • 8

2 Answers2

1

If there's an update on the server-side, you have to make an API call to get the latest value. That is the only way a client will know the updated value from the server. Once you get the new value from the value, you can use localStorage.setItem(key, value) to set in the localStorage of your browser. Hope this helps.

Sai Charan
  • 113
  • 2
  • 8
0

You either have to recheck every x number of seconds or check on page load. Either way there is no automatic way for the page to know it's outdated without you telling it to check if there is an update and update accordingly.