DEV Community

Discussion on: Custom React Hooks: useLocalStorage

Collapse
 
link2twenty profile image
Andrew Bone

It would be nice to have an event listener like syntax to know if local storage has been updated.

Collapse
 
iamludal profile image
Ludal 🚀

Actually it is possible (see Window: storage event)
Is it what you're looking for? 🤔

Collapse
 
link2twenty profile image
Andrew Bone

I think that only applies if another session makes the change.

I was more thinking component-A makes a change to settings.sound and component-B has an event listener that means it can see the change without having to drill props.

Thread Thread
 
iamludal profile image
Ludal 🚀 • Edited

Ok I got you, and you're right, it would be useful. In that case, I think I'd go with the useContext hook.