DEV Community

Discussion on: How to add a dark mode to your React web app

Collapse
 
arnu515 profile image
arnu515

You're writing longer, more complicated code. For example, instead of writing

checked: localStorage.getItem("theme") === "dark" ? true : false,

You can write:

checked: localStorage.getItem("theme") === "dark",

because localStorage.getItem("theme") === "dark" is a boolean and its value will be true or false.

Also, instead of writing

document.getElementsByTagName("HTML")[0]

You can write

document.querySelector("html")

and it will do the same thing.

There's nothing wrong with your code, but I'm just telling you how to make it more efficient