DEV Community

Discussion on: How to syncing React state across multiple tabs with useState Hook and localStorage

Collapse
 
link2twenty profile image
Andrew Bone

Interesting stuff, using local storage is so powerful.

I took this principle a little further in a post a wrote a while ago. I needed to listen internally local storage change so I made a storage hook that comes with its own listening style system. The multi-tab stuff was a happy accident I leaned into.

Here's a basic demo and here's the article I wrote about it in.

Collapse
 
cassiolacerda profile image
Cássio Lacerda

Your useLocalStorage custom hook written in Typescript is very interesting, congrats!

LocalStorage is really powerfull, but I have noticed that in cases with a lot of changes happening at the same time, the performance is poor, due to the excessive usage of JSON.parse and JSON.stringify. I started some tests with IndexedDB and maybe it can handle this scenario better than localStorage.