DEV Community

Discussion on: HowTo: Custom React localStorage Hook ⚓

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

I would just say that your hook doesn't actually update when two components both set the value independently. An event system to ensure that all hooks using "theme" or whatever changed at once would make this much more powerful.

I don't mean to be overly negative, it's really nice :)

Collapse
 
sanderdebr profile image
sanderdebr • Edited

True thanks for the tip! Hooking this up to, for example, a useReducer() hook would ensure a global state like that, but I thought it would be outside of this tutorial.

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

Ah I was thinking of adding and event handler for window 'storage' event using useEffect and then refreshing the value if it changed.