← スキル一覧に戻る

implementing-code-splitting
by djankies
⭐ 0🍴 0📅 2025年11月25日
SKILL.md
name: implementing-code-splitting description: Teaches code splitting with lazy() and Suspense in React 19 for reducing initial bundle size. Use when implementing lazy loading, route-based splitting, or optimizing performance. allowed-tools: Read, Write, Edit version: 1.0.0
Code Splitting with lazy() and Suspense
Basic Pattern
import { lazy, Suspense } from 'react';
const HeavyComponent = lazy(() => import('./HeavyComponent'));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<HeavyComponent />
</Suspense>
);
}
Route-Based Splitting
import { lazy, Suspense } from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
const Home = lazy(() => import('./pages/Home'));
const Dashboard = lazy(() => import('./pages/Dashboard'));
const Settings = lazy(() => import('./pages/Settings'));
function App() {
return (
<BrowserRouter>
<Suspense fallback={<PageLoader />}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/settings" element={<Settings />} />
</Routes>
</Suspense>
</BrowserRouter>
);
}
Component-Based Splitting
import { lazy, Suspense, useState } from 'react';
const Chart = lazy(() => import('./Chart'));
const Table = lazy(() => import('./Table'));
function DataView() {
const [view, setView] = useState('chart');
return (
<>
<button onClick={() => setView('chart')}>Chart</button>
<button onClick={() => setView('table')}>Table</button>
<Suspense fallback={<Spinner />}>
{view === 'chart' ? <Chart /> : <Table />}
</Suspense>
</>
);
}
Named Exports
const { BarChart } = await import('./Charts');
export const BarChart = lazy(() =>
import('./Charts').then(module => ({ default: module.BarChart }))
);
For comprehensive code splitting patterns, see: research/react-19-comprehensive.md lines 1224-1238.
スコア
総合スコア
60/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です