News for hackers. Stuff that matters.
Re:Persisting React State in LocalStorage by the_gipsy on Friday February 28, 2020 @01:11PM (#22444884)
Ok I see your point, LS might be the right place to save such a state.

However, I still disagree on doing it on a component level (with hooks or whatever). If I log out, that LS should be gone in most cases. Either the logout must know too much about specific components (leaky abstraction), or the components will need to handle too many edge cases.

Re:Persisting React State in LocalStorage by foota on Friday February 28, 2020 @01:21PM (#22444994)
Perhaps you could build the LS storage on top of a per-profile local storage?

I.e., you have something that on login creates a local storage key value for the active user, and then when someone logs out that is cleared (or it's keyed by user id and only used when that user is logged in). Components adding something need to add it to that key somehow, or could make use of prefixes. (the lack of structured data in local storage hurts a little here)

This way the thing managing the profile doesn't need to know what people are storing, and the components can still clear on logout.

Re:Persisting React State in LocalStorage by pault on Friday February 28, 2020 @02:42PM (#22445678)
I consider this a best practice. I always key my localstorage values to the user account and build version so you don't get issues with old localstorage schemas causing bugs when a new build is released.
Re:Persisting React State in LocalStorage by hjnilsson on Friday February 28, 2020 @03:44PM (#22446172)
I would suggest just calling clearAll on localStorage upon logout. To keep it simple.