我想在切换到暗模式时更改我的标志图片(我正在使用tailwind上的类)。这有机会实现吗?
这是我用来改变主题的钩子:
const useTheme = () => {
const [theme, setTheme] = useState(localStorage.theme);
const nextTheme = theme === "light" ? "dark" : "light";
useEffect(() => {
const rootElement = window.document.documentElement;
rootElement.classList.remove(nextTheme);
rootElement.classList.add(theme);
localStorage.setItem("theme", theme);
}, [theme, nextTheme]);
return [nextTheme, setTheme];
};
这是我想要更改的图片(如果有帮助):
<div className="flex flex-col">
<Link
to="/"
className="flex px-5 gap-2 my-6 pt-1 w-190 items-center"
onClick={handleCloseSideBar}
>
<img src="/img/logo.png" alt="logo" className="w-full" />
</Link>
</div>;