fe-refactor
1
总安装量
1
周安装量
#45781
全站排名
安装命令
npx skills add https://github.com/ingpdw/pdw-fe-dev-tool --skill fe-refactor
Agent 安装分布
mcpjam
1
claude-code
1
replit
1
junie
1
windsurf
1
zencoder
1
Skill 文档
FE Refactoring
$ARGUMENTSë¡ ì ë¬ë íì¼ì ì½ë를 ë¶ìíê³ ë¦¬í©í ë§íë¤.
리í©í ë§ ì ì°¨
- íì¬ ì½ë ë¶ì: ëì íì¼ê³¼ ê´ë ¨ íì¼ì ì½ê³ 구조를 íì íë¤
- 문ì ì ì§ë¨: ìë í¨í´ 목ë¡ìì í´ë¹íë í목ì ìë³íë¤
- 리í©í ë§ ê³í ì ì: ë³ê²½ ì¬íì ì¬ì©ììê² ì¤ëª íê³ ì¹ì¸ì ë°ëë¤
- 리í©í ë§ ì¤í: ì¹ì¸ë ë³ê²½ ì¬íì ì ì©íë¤
- ê²ì¦: ë³ê²½ í 기존 í ì¤í¸ê° íµê³¼íëì§ íì¸íë¤
리í©í ë§ í¨í´
ì»´í¬ëí¸ ë¶ë¦¬
200ì¤ ì´ìì´ê±°ë 2ê° ì´ìì ì± ìì ê°ì§ ì»´í¬ëí¸ë¥¼ ë¶ë¦¬íë¤.
Before:
function Dashboard() {
// ì¬ì©ì ë°ì´í° ë¡ì§
const [user, setUser] = useState(null);
useEffect(() => { fetchUser().then(setUser); }, []);
// ì°¨í¸ ë°ì´í° ë¡ì§
const [chartData, setChartData] = useState([]);
useEffect(() => { fetchChartData().then(setChartData); }, []);
return (
<div>
<header>{user?.name}</header>
<div>{/* ë³µì¡í ì°¨í¸ ë ëë§ */}</div>
<div>{/* ë³µì¡í í
ì´ë¸ ë ëë§ */}</div>
</div>
);
}
After:
function Dashboard() {
return (
<div>
<DashboardHeader />
<DashboardChart />
<DashboardTable />
</div>
);
}
커ì¤í í ì¶ì¶
ìí + ì´íí¸ ë¡ì§ì´ ê²°í©ë í¨í´ì í ì¼ë¡ ì¶ì¶íë¤.
Before:
function ProductList() {
const [products, setProducts] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
useEffect(() => {
setLoading(true);
fetchProducts()
.then(setProducts)
.catch(setError)
.finally(() => setLoading(false));
}, []);
// ... ë ëë§
}
After:
// hooks/useProducts.ts
function useProducts() {
return useQuery({
queryKey: ["products"],
queryFn: fetchProducts,
});
}
// components/ProductList.tsx
function ProductList() {
const { data: products, isLoading, error } = useProducts();
// ... ë ëë§
}
useEffect ì ê±° (Derived State)
useEffectë¡ ê³ì°íë íì ìí를 useMemo ëë ë ëë§ ì¤ ê³ì°ì¼ë¡ ëì²´íë¤.
Before:
const [items, setItems] = useState([]);
const [filteredItems, setFilteredItems] = useState([]);
const [search, setSearch] = useState("");
useEffect(() => {
setFilteredItems(items.filter((i) => i.name.includes(search)));
}, [items, search]);
After:
const [items, setItems] = useState([]);
const [search, setSearch] = useState("");
const filteredItems = items.filter((i) => i.name.includes(search));
Server/Client Component ë¶ë¦¬
í´ë¼ì´ì¸í¸ ë¡ì§ì ìµìíì Client Componentë¡ ê²©ë¦¬íë¤.
Before:
"use client"; // ì ì²´ê° í´ë¼ì´ì¸í¸
export default function ProductPage() {
const [count, setCount] = useState(0);
const products = useProducts(); // ìë²ìì ê°ì ¸ì¬ ì ìë ë°ì´í°
return (
<div>
<h1>Products</h1>
<ProductList products={products} />
<Counter count={count} onChange={setCount} />
</div>
);
}
After:
// page.tsx (Server Component)
export default async function ProductPage() {
const products = await getProducts();
return (
<div>
<h1>Products</h1>
<ProductList products={products} />
<Counter /> {/* Client Component */}
</div>
);
}
Compound Component í¨í´
ê´ë ¨ ì»´í¬ëí¸ë¤ì ê²°í©ëê° ëì ë ì ì©íë¤.
// Before: propsë¡ ëª¨ë ê²ì ì ë¬
<Select options={options} label="Country" placeholder="Select..." onChange={onChange} />
// After: Compound Component
<Select value={value} onValueChange={onChange}>
<SelectTrigger>
<SelectValue placeholder="Select..." />
</SelectTrigger>
<SelectContent>
{options.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
íì ìì ì± ê°í
// Before: ëì¨í íì
function handleResponse(data: any) {
return data.items.map((item: any) => item.name);
}
// After: ì격í íì
interface ApiResponse {
items: Array<{ name: string; id: string }>;
}
function handleResponse(data: ApiResponse) {
return data.items.map((item) => item.name);
}
Barrel Export ì 리
// components/user/index.ts
export { UserProfile } from "./UserProfile";
export { UserAvatar } from "./UserAvatar";
export { UserSettings } from "./UserSettings";
export type { UserProfileProps } from "./UserProfile";
ì¤í ê·ì¹
- ì¸ìê° ìì¼ë©´ ì¬ì©ììê² ë¦¬í©í ë§ ëìì ì§ë¬¸íë¤
- 리í©í ë§ ì ë°ëì íì¬ ì½ë를 ì½ê³ ì´í´íë¤
- ë³ê²½ ê·ëª¨ê° í° ê²½ì° ë¨ê³ë³ë¡ ëë ì ì§ííë¤
- 기존 í ì¤í¸ê° ìì¼ë©´ 리í©í ë§ í 깨ì§ì§ ìëì§ íì¸íë¤
- ê¸°ë¥ ë³ê²½ ìì´ êµ¬ì¡°ë§ ê°ì íë¤ (ëì ë³´ì¡´)
- íë¡ì í¸ì 기존 í¨í´ê³¼ ì¼ê´ì±ì ì ì§íë¤