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:
@@ -22,6 +22,7 @@ import {
|
||||
actionDeleteDeck,
|
||||
actionGetDecksByUserId,
|
||||
actionUpdateDeck,
|
||||
actionGetDeckById,
|
||||
} from "@/modules/deck/deck-action";
|
||||
import type { ActionOutputDeck } from "@/modules/deck/deck-action-dto";
|
||||
|
||||
@@ -148,17 +149,25 @@ export function DecksClient({ userId }: DecksClientProps) {
|
||||
const [decks, setDecks] = useState<ActionOutputDeck[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const loadDecks = async () => {
|
||||
setLoading(true);
|
||||
const result = await actionGetDecksByUserId(userId);
|
||||
if (result.success && result.data) {
|
||||
setDecks(result.data);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let ignore = false;
|
||||
|
||||
const loadDecks = async () => {
|
||||
setLoading(true);
|
||||
const result = await actionGetDecksByUserId(userId);
|
||||
if (!ignore) {
|
||||
if (result.success && result.data) {
|
||||
setDecks(result.data);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadDecks();
|
||||
|
||||
return () => {
|
||||
ignore = true;
|
||||
};
|
||||
}, [userId]);
|
||||
|
||||
const handleUpdateDeck = (deckId: number, updates: Partial<ActionOutputDeck>) => {
|
||||
@@ -176,8 +185,11 @@ export function DecksClient({ userId }: DecksClientProps) {
|
||||
if (!deckName?.trim()) return;
|
||||
|
||||
const result = await actionCreateDeck({ name: deckName.trim() });
|
||||
if (result.success) {
|
||||
loadDecks();
|
||||
if (result.success && result.deckId) {
|
||||
const deckResult = await actionGetDeckById({ deckId: result.deckId });
|
||||
if (deckResult.success && deckResult.data) {
|
||||
setDecks((prev) => [...prev, deckResult.data!]);
|
||||
}
|
||||
} else {
|
||||
toast.error(result.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user