DEV Community

Discussion on: Persisting React State in localStorage

Collapse
 
fmgordillo profile image
Facundo Martin Gordillo • Edited

Awesome post!!

Additional things to consider, if someone wants to implement this:

1) If you are concern about variable type, you should make additional changes into useStickyState() by two ways: Detecting the variable inside the function or passing an additional arg (i.e: 'integer')
2) "The label you give it has to be unique", one option for that could be creating a Set outside the function, and control if that label is being created or not, and throw a warning in the code.

But that's too fancy and all, I really prefer your solution :)

And welcome to Dev.to ;)