dm
Persisting React State in LocalStorage | Hacker News

Hacker News new | past | comments | ask | show | jobs | submit login Persisting React State in LocalStorage ( joshwcomeau.com ) 55 points by joshwcomeau 2 hours ago | hide | past | web | favorite | 27 comments geocar 1 hour ago I'd recommend just putting this crap in the URL. That way (a) the server could see it too, and (b) users could share their state by sharing the URL (which makes supporting them easier!). If you've got so much state this doesn't make sense, then ¯\_(ツ)_/¯ I suppose caching it in localStorage is fine, but I haven't yet run into this problem. Having a setSticky((k,v) => that modifies the url with the history API is pretty easy, and if you get the results using the Context API, you can have your root monitor the URL (again using the history API) and publish the result using a context so you don't have a storm of updates. reply ...

Linked on 2020-02-28 19:25:06 | Similar Links