DEV Community

loading...

Discussion on: The Perfect Dark Mode

Collapse
stativka profile image
Eugene Stativka

I’m not sure that the localstorage is the best option to persist this setting. Have you considered cookies and setting data-theme attribute during SSR?

Collapse
sreetamdas profile image
Sreetam Das Author • Edited

I really didn't want to resort to cookies 😬
and to persist this setting on SSR would mean needing to keep a DB I think? I'm open to other suggestions if you've got any!

Collapse
stativka profile image
Eugene Stativka

No DB involved. You parse cookies during SSR and add the data-theme attribute on the server. On the client you update cookies every time you change the setting.