We are currently living in a dark mode in everything era. Most apps nowadays come with a switch either at the navbar or just somewhere around its s...
For further actions, you may consider blocking this person and/or reporting abuse
Very nice! Great idea storing it in localstorage so it's the same when the user comes back the next time.
Also love the variables in CSS - I definitely didn't know that those were supported outside of scss, etc!
Yes if you close that tab and come visit the link again it will still be the theme you last set
Pst, I gave it a spin and implemented it using hooks, here's the comparison gist.github.com/Oxyrus/b4edab0372b... (doesn't include the fancy toggle because I was lazy 😆)
Cool, I would have used useLocalState from the use-hooks package.
Nice 💯
You're writing longer, more complicated code. For example, instead of writing
You can write:
because
localStorage.getItem("theme") === "dark"
is a boolean and its value will be true or false.Also, instead of writing
You can write
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
Question, what's the point of having a
theme
property inside your state? I don't see you using it anywhere.I kinda forgot to remove it. Before I was using the theme value to toggle the theme change
WOW 🤩 Simple and directly to the point!
Thank you for posting, I’ll use your guide as starting point.
Anytime