countries api solution w/ typescript, axios, modularized scss
Design comparison
Solution retrospective
How can I improve darkMode handling without having to pass a variable through the dom tree?
Any other suggestion is more than welcome!
Community feedback
- @BasharKhdr1992Posted almost 2 years ago
If you are using a library like React, or VueJs, you can make use of context api or Redux, or Redux Toolkit (in react for example) or Vuex (in case of vue) to create a global state for Dark/light theme. In this way there is no longer need to pass props down the dom tree multiple levels to implement a theme switcher. Instead, you save all state variables related to themes in one central point, and any component that have multiple themes can directly get access to the global state using context (again in case of react).
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord