Skip to content

Commit

Permalink
chore: improve theme-management cookbook (#7117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane-Donlon authored Dec 2, 2024
1 parent 76967c1 commit 0f937fc
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,25 @@ module.exports = {
Then we have to add this code in the head tag of our ```root.tsx``` file.

```js
<script
<script
dangerouslySetInnerHTML={`
(function() {
function setTheme(theme) {
document.documentElement.className = theme;
localStorage.setItem('theme', theme);
}
var theme = localStorage.getItem('theme');
console.log(theme);
const theme = localStorage.getItem('theme');
if (theme) {
setTheme(theme);
} else {
setTheme('light');
}
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
setTheme('dark');}
else {
setTheme('light');}}
})();
window.addEventListener('load', function() {
var themeSwitch = document.getElementById('hide-checkbox');
const themeSwitch = document.getElementById('hide-checkbox');
themeSwitch.checked = localStorage.getItem('theme') === 'light'? true: false;
}
);
Expand Down

0 comments on commit 0f937fc

Please sign in to comment.