DEV Community

Discussion on: Persistent State in React

Collapse
alirezavalizade profile image
alireza valizade

Cool, thanks for writing, But this is not a good way of persistent state, You'll get performance issues, because DOM will be blocked LS. Better is just keep the state in simple key-value object, then we can set it to storage before leaving the page, or in specific amount of time.

Collapse
jamesthomson profile image
James Thomson

Why would the DOM be blocked? Maybe the main thread could be if the operation was huge, but if this is the case, you shouldn't be storing massive amounts of data in localStorage.

Collapse
alirezavalizade profile image
alireza valizade

Yes, exactly my pointe was it's not for saving huge data, better to use do not that on each render or change or even better to use IndexedDB, Check this out it's an example of blocking the ui by localStorage,
codepen.io/SitePoint/pen/GzLPJV

Thread Thread
jamesthomson profile image
James Thomson • Edited on

Well, if anything, that actually proves how capable writing to localStorage can be. The fact that it can write 100,000 entries in less than 500ms is pretty impressive. Nonetheless, each use case has its ideal solution. I wouldn’t rule out this method because of an over amplified scenario such as writing 100,000 entries to localStorage