← スキル一覧に戻る

react-patterns
by Joshua-Palamuttam
⭐ 0🍴 0📅 2025年12月8日
SKILL.md
name: react-patterns description: React component patterns including functional components, hooks, state management, API integration, loading/error states, and event handlers. Use when creating or reviewing React components.
React Patterns
Overview
These patterns ensure consistent, maintainable React components with TypeScript. Follow these guidelines for all frontend development.
Component Structure
Functional Components Only
Always use functional components with hooks:
export function TaskList({ tasks, onTaskClick }: TaskListProps) {
return (
<ul className="task-list">
{tasks.map(task => (
<TaskItem key={task.id} task={task} onClick={onTaskClick} />
))}
</ul>
);
}
Component File Structure
components/
├── TaskList/
│ ├── TaskList.tsx # Component implementation
│ ├── TaskList.css # Component styles
│ └── index.ts # Re-export
TypeScript Interfaces
Props Interfaces
Define props interfaces for every component:
interface TaskListProps {
tasks: Task[];
onTaskClick: (task: Task) => void;
isLoading?: boolean;
}
export function TaskList({ tasks, onTaskClick, isLoading = false }: TaskListProps) {
// ...
}
State Management
useState for Local State
const [title, setTitle] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
useEffect for Side Effects
useEffect(() => {
fetchTasks();
}, []);
Loading and Error States
Always Handle All States
if (isLoading) {
return <div className="loading">Loading tasks...</div>;
}
if (error) {
return <div className="error">Error: {error}</div>;
}
if (tasks.length === 0) {
return <div className="empty">No tasks yet. Create one!</div>;
}
Event Handlers
Naming Convention
Prefix with handle for component handlers, on for props:
interface TaskItemProps {
task: Task;
onComplete: (id: string) => void; // Prop callback
}
function TaskItem({ task, onComplete }: TaskItemProps) {
function handleCompleteClick() { // Local handler
onComplete(task.id);
}
// ...
}
CSS Styling
Component-Scoped CSS
Each component has its own CSS file with BEM-like naming:
.task-list- Block.task-item- Element.task-item.completed- Modifier
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です