fix: 修复 React Compiler 严格模式下的 lint 错误
- Memorize: 将 loadCards 内联到 useEffect 中避免变量提升问题 - DecksClient: 修复 effect 中异步加载,创建 deck 后使用 actionGetDeckById - LanguageSettings: 使用 effect 设置 cookie 避免 render 期间修改 - theme-provider: 修复 hydration 逻辑避免 render 期间访问 ref
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import { Languages } from "lucide-react";
|
||||
import { cn } from "@/utils/cn";
|
||||
|
||||
@@ -17,6 +17,7 @@ const languages = [
|
||||
|
||||
export function LanguageSettings() {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [pendingLocale, setPendingLocale] = useState<string | null>(null);
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -46,10 +47,16 @@ export function LanguageSettings() {
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const setLocale = async (locale: string) => {
|
||||
document.cookie = `locale=${locale}`;
|
||||
window.location.reload();
|
||||
};
|
||||
useEffect(() => {
|
||||
if (pendingLocale) {
|
||||
document.cookie = `locale=${pendingLocale}; path=/`;
|
||||
window.location.reload();
|
||||
}
|
||||
}, [pendingLocale]);
|
||||
|
||||
const setLocale = useCallback((locale: string) => {
|
||||
setPendingLocale(locale);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="relative" ref={menuRef}>
|
||||
|
||||
Reference in New Issue
Block a user