Skip to content

How can I set my page switch to dark theme anytime when users reload or re-open my home page? #2808

Answered by george-gca
DoHaiSon asked this question in Q&A
Discussion options

You must be logged in to vote

The line responsible for storing this information is this:

localStorage.setItem("theme", themeSetting);

Now, I don't think removing it is a good choice, because probably every new page you open might always load the dark theme even though the light one was selected. I believe the best for you is to set the default as the dark theme instead of getting the system preference from the user (but only on the first load):

themeSetting = "system";

or even disable light theme.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DoHaiSon
Comment options

Answer selected by DoHaiSon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants