diff --git a/src/components/ToggleTheme.jsx b/src/components/ToggleTheme.jsx index c64cba3..f736d2e 100644 --- a/src/components/ToggleTheme.jsx +++ b/src/components/ToggleTheme.jsx @@ -1,7 +1,10 @@ import { useState, useEffect } from "react"; function ToggleTheme() { - const [theme, setTheme] = useState('auto'); + const [theme, setTheme] = useState(() => { + const savedTheme = localStorage.getItem('theme'); + return savedTheme || 'auto'; + }); const themeAuto = () => ( ) @@ -13,6 +16,7 @@ function ToggleTheme() { } else { root.setAttribute('data-theme', theme); } + localStorage.setItem('theme', theme); }, [theme]); const toggleTheme = () => {