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
Neto
Neto4mo ago
do you want to persist between different devices? if no db if its enough to handle local state only, localstorage is good enough
Noor
Noor4mo ago
I am not sure. Does it needs to be persistent?? It's just settings of an app
Neto
Neto4mo ago
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
Noor
Noor4mo ago
Settings like Theme color Show/Hide Tags on Startup Show/Hide Deadline by default Like this
Neto
Neto4mo ago
its fine to keep in the client side
Pronsh
Pronsh4mo ago
Imo it makes more sense to cache in client side
Neto
Neto4mo ago
if you dont want to flash content, then its server side
Pronsh
Pronsh4mo ago
Since small
Noor
Noor4mo ago
Hmm I guess settings are not that important. I mean user rarely changes the device So I can store in Localstorage
Neto
Neto4mo ago
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
Huge Letters
Huge Letters4mo ago
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
GStudiosX2
GStudiosX24mo ago
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