Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
fix: 解决css变量报错
gaoSir52a2d589e4e7
diff --git a/src/app/hooks/useCssVariables.ts b/src/app/hooks/useCssVariables.tsindex 41a85529..65108714 100644--- a/src/app/hooks/useCssVariables.ts+++ b/src/app/hooks/useCssVariables.ts@@ -1,3 +1,5 @@+"use client";+import { useState, useEffect } from "react";/**@@ -18,10 +20,14 @@ const useCssVariables = ("--theColor8","--theColor9",],- element: HTMLElement = document.documentElement,+ element?: HTMLElement,): Record<string, string> => {const [variables, setVariables] = useState<Record<string, string>>({});+ if (typeof window === "undefined") return variables;++ element = element || document.documentElement;+useEffect(() => {const handleVariableChange = () => {const computedStyle = getComputedStyle(element);