Responsive Dashboard TailwindCss and React

Solution retrospective
What has been most difficult for me has been making Tailwind change the background color of the screen between dark and light. In the end I solved it with the following code
const [isDarkMode, setIsDarkMode] = useState(false);
useEffect(() => { if (isDarkMode) { document.body.classList.add("dark", "bg-Very-Dark-Blue"); document.body.classList.remove("bg-white"); } else { document.body.classList.remove("dark", "bg-Very-Dark-Blue"); document.body.classList.add("bg-white"); } }, [isDarkMode]);
const toggleDarkMode = () => { setIsDarkMode(!isDarkMode); };
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on alvnavraii's solution.
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord