@mickyginger
Posted
Hi Berta, this looks great! ๐
I like your approach for setting the theme by loading in different stylesheets but I wonder if it would be more performant to set a class on the HTML when the user toggles the theme, then apply different styles based on that class... Something like:
function handleToggle(e) {
const htmlElem = document.querySelector('html')
htmlElem.classList.remove('light', 'dark');
htmlElem.classList.add(e.target.checked ? 'dark' : 'light');
}
Then in your SCSS:
/* base styles here */
html.dark {
/* dark styles here */
}
html.light {
/* light styles here */
}
Hope that's helpful!
Marked as helpful