t-convex-nextjs-saas/src/components/core/ThemeChanger.tsx

29 lines
630 B
TypeScript
Raw Normal View History

2026-03-27 23:15:07 +00:00
"use client";
import { useTheme } from "@wrksz/themes/client";
import { useSyncExternalStore } from "react";
2026-03-27 23:15:07 +00:00
export const ThemeChanger = () => {
const { theme, setTheme } = useTheme();
const mounted = useSyncExternalStore(
() => () => undefined,
() => true,
() => false,
);
if (!mounted) {
return <p>Loading theme...</p>;
}
2026-03-27 23:15:07 +00:00
return (
<div>
<p>The current theme is: {theme}</p>
<button type="button" onClick={() => setTheme("light")}>
Light Mode
</button>
<button type="button" onClick={() => setTheme("dark")}>
Dark Mode
</button>
2026-03-27 23:15:07 +00:00
</div>
);
};