DB or Localstorage?
Hey everyone, I want to store the settings/preference of users
For example
If I have to store color preference, theme preference, sound preferences or any settings related preferences
So should I store it in Database and every time user loads the react app, it will be fetched and those settings will be applied
Or should I store them in localstorage and then apply settings??
12 Replies
do you want to persist between different devices? if no db
if its enough to handle local state only, localstorage is good enough
I am not sure. Does it needs to be persistent??
It's just settings of an app
you tell me
depends on the setting
if is audio, sure storing on the device is fine
if its a setting that impacts the operations, always in the db
like a feature toggle
Settings like
Theme color
Show/Hide Tags on Startup
Show/Hide Deadline by default
Like this
its fine to keep in the client side
Imo it makes more sense to cache in client side
if you dont want to flash content, then its server side
Since small
Hmm I guess settings are not that important. I mean user rarely changes the device
So I can store in Localstorage
yep
as long as its fine to have a delay between page startup and settings sync
akin to dark more on local storage
its ssr'd as white theme but gets dark after
stuff like color preference could be stored in cookies so that you could access them on the server for proper ssr and avoid content flashing.
stuff like sound preferences is fine for localStorage since I assume those don't matter on initial render
I store theme in local storage and its fine theres a little flash but its basically instant
I have like JavaScript some where to change the theme
Though im not using nextjs so maybe its different there