Skip to content

Instantly share code, notes, and snippets.

@mebiusbox
Last active December 25, 2025 05:36
Show Gist options
  • Select an option

  • Save mebiusbox/1d0841d1824e8d85752bd2dd8f867f21 to your computer and use it in GitHub Desktop.

Select an option

Save mebiusbox/1d0841d1824e8d85752bd2dd8f867f21 to your computer and use it in GitHub Desktop.
vite_js
import { useEffect, useState } from "react";
const useDarkMode = () => {
// const [enabled, setEnabled] = useLocalStorage('dark-theme');
const [enabled, setEnabled] = useState(false);
const isEnabled = typeof enabledState === 'undefined' && enabled;
useEffect(() => {
const className = 'dark';
const bodyClass = window.document.body.classList;
isEnabled ? bodyClass.add(className) : bodyClass.remove(className);
}, [enabled, isEnabled]);
return [enabled, setEnabled];
};
export default useDarkMode;
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs) {
return twMerge(clsx(inputs));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment