4

I am persisting the redux state to local storage in my react app so that i can use the persisted state across all tabs. But i could no where find how to clear it when browser closes. Currently the state present in local storage of browser is staying until i manually clear it. Even i tried using session storage but it is not available across browser tabs. Is their any option that i can clear the persisted store on closing the browser.

Candy
  • 654
  • 2
  • 10
  • 24
  • 1
    Have you tried something like that localStorage.clear() ? – KT-mongo Dec 04 '18 at 08:47
  • 1
    *Even i tried using session storage but it is not available across browsers* - no, it is, https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage#Browser_compatibility . You have XY problem. You're trying to do a weird thing that shouldn't generally be done. If you have problems with sessionStorage, consider addressing them directly. – Estus Flask Dec 04 '18 at 08:47
  • See https://stackoverflow.com/questions/20325763/browser-sessionstorage-share-between-tabs . localStorage can act as temporary storage. At this point I don't see problems if persists. As any cache, it can be invalidated with timestamps. – Estus Flask Dec 04 '18 at 08:54
  • Possible duplicate of [How to delete a localStorage item when the browser window/tab is closed?](https://stackoverflow.com/questions/9943220/how-to-delete-a-localstorage-item-when-the-browser-window-tab-is-closed) – Henrik Andersson Dec 05 '18 at 08:45

0 Answers0