re: HowTo: Custom React localStorage Hook ⚓ VIEW POST


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 :)


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.


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

code of conduct - report abuse