Y
Y
yumakaev2020-05-26 15:46:38
React
yumakaev, 2020-05-26 15:46:38

How to update a component depending on localstorage state?

I have two pages

localhost:3000 and 1.localhost:3000, after some actions I do a redirect and transfer some data from localhost:3000 to 1.localhost:3000, I get this data on the second page, but only after updating it, how to get this data on the first redirect? To avoid having to update the second page? (The data is in localstorage)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-05-26
@yumakaev

You need to write a listener (watcher). For example,

const interval = setInterval(() => {
   const myitem = window.localStorage.getItem('MYITEM');
   if (myitem) {
       clearInterval(interval);
   }
   // дальнейшие действия с myitem
}, 1000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question