donavon / use-dark-mode

A custom React Hook to help you implement a "dark mode" component.
MIT License
1.28k stars 100 forks source link

How to apply the dark-mode/light mode class on an element with a specific classname or id name? #78

Closed silenceofthewans closed 3 years ago

silenceofthewans commented 3 years ago

fixed

MindsetZack commented 3 years ago

Hey just wondering what was your solution to this issue? Trying to do this myself but having no luck at the moment. Thanks for your help

silenceofthewans commented 3 years ago

@MindsetZack I didn't use use-dark-mode and created my own dark mode logic which is basically checking state of a toggle and if its true then adding couple of dark mode classes on elements that I want a different color scheme on and when it's false removing them, there's couple of ways to do that like document methods or passing props and switching styles based on props using styled-components. If you then want to save the dark mode state in localStorage you can save your toggle value in a useState hook that stores in localStorage like this one .