-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π€π β Experimenting with some accessibility designs
- Loading branch information
1 parent
7381e5e
commit c40c442
Showing
2 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export const useDarkMode = (): [boolean, () => void] => { | ||
const [isDarkMode, setIsDarkMode] = useState(false); | ||
|
||
useEffect(() => { | ||
const savedMode = localStorage.getItem('darkMode'); | ||
setIsDarkMode(savedMode === 'true'); | ||
}, []); | ||
|
||
const toggleDarkMode = () => { | ||
const newMode = !isDarkMode; | ||
setIsDarkMode(newMode); | ||
localStorage.setItem('darkMode', String(newMode)); | ||
document.documentElement.classList.toggle('dark', newMode); | ||
}; | ||
|
||
return [isDarkMode, toggleDarkMode]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters