Skip to content

Commit 4113ae1

Browse files
committed
优化 MyDesigns 组件,移除不必要的 useEffect,直接从设计存储加载初始设计;更新 Design 接口中的 schema 类型为 Record<string, unknown>
1 parent 79a968f commit 4113ae1

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

apps/playground/src/pages/MyDesigns.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react';
1+
import { useState } from 'react';
22
import { useNavigate } from 'react-router-dom';
33
import { designStorage, Design } from '../services/designStorage';
44
import {
@@ -18,17 +18,14 @@ import {
1818

1919
export const MyDesigns = () => {
2020
const navigate = useNavigate();
21-
const [designs, setDesigns] = useState<Design[]>([]);
21+
// Load initial designs from storage to avoid useEffect cascading render
22+
const [designs, setDesigns] = useState<Design[]>(() => designStorage.getAllDesigns());
2223
const [searchQuery, setSearchQuery] = useState('');
2324
const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid');
2425
const [showImportModal, setShowImportModal] = useState(false);
2526
const [importJson, setImportJson] = useState('');
2627
const [importName, setImportName] = useState('');
2728

28-
useEffect(() => {
29-
loadDesigns();
30-
}, []);
31-
3229
const loadDesigns = () => {
3330
setDesigns(designStorage.getAllDesigns());
3431
};

apps/playground/src/services/designStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Design {
88
id: string;
99
name: string;
1010
description?: string;
11-
schema: any;
11+
schema: Record<string, unknown>;
1212
createdAt: string;
1313
updatedAt: string;
1414
isTemplate?: boolean;

0 commit comments

Comments
 (0)