refactor(theme): use useSyncExternalStore for theme hydration
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
a1e653bbf7
commit
eec41123ef
1 changed files with 6 additions and 6 deletions
|
|
@ -1,14 +1,14 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useTheme } from "@wrksz/themes/client";
|
import { useTheme } from "@wrksz/themes/client";
|
||||||
import { useEffect, useState } from "react";
|
import { useSyncExternalStore } from "react";
|
||||||
|
|
||||||
export const ThemeChanger = () => {
|
export const ThemeChanger = () => {
|
||||||
const { theme, setTheme } = useTheme();
|
const { theme, setTheme } = useTheme();
|
||||||
const [mounted, setMounted] = useState(false);
|
const mounted = useSyncExternalStore(
|
||||||
|
() => () => undefined,
|
||||||
useEffect(() => {
|
() => true,
|
||||||
setMounted(true);
|
() => false,
|
||||||
}, []);
|
);
|
||||||
|
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return <p>Loading theme...</p>;
|
return <p>Loading theme...</p>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue