DEV Community

Discussion on: How to persist data to localStorage in React with hooks.

Collapse
 
wseai profile image
jagarkin • Edited

using localStorage as a database for your project, is not a good practice for many reasons:

  • It can only store string data (you could serialize everything including data types into local storage, but that's an ugly hack.)

  • It is synchronous ( This means each local storage operation you run will be one-at-a-time it will slow your app )

  • It can't be used by web workers ( This means that if you want to build an application that takes advantage of background processing for performance, chrome extensions, things like that: you can't use local storage at all since it isn't available to the web workers. )

  • It still limits the size of data you can store ( 5mb )

  • unprotected JavaScript ( vulnerable to XSS )

  • when user clear cache data will be lost

Collapse
 
gautham495 profile image
Gautham Vijayan

Yes sir for a personal project for beginners it is a good hack to learn. But for a production app, no way I am using localstorage.
Cheers.