Back to list
Soki0909

react-component

by Soki0909

Webアプリ:ポートフォリオサイト用のリポジトリ

0🍴 0📅 Jan 18, 2026

SKILL.md


name: react-component description: React + TypeScript コンポーネント作成ガイド

React コンポーネント作成スキル

このプロジェクトでのReactコンポーネント作成規約とベストプラクティス。

ディレクトリ構造

src/
├── components/      # 共通コンポーネント
├── pages/           # ページコンポーネント
├── hooks/           # カスタムフック
├── contexts/        # React Context
├── types/           # 型定義
└── utils/           # ユーティリティ

コンポーネント作成手順

1. 型を先に定義する

src/types/dataModels.ts に型を追加:

export interface NewComponentProps {
  title: string;
  items: string[];
  onAction?: () => void;
}

2. コンポーネントを作成

import type { NewComponentProps } from '../types/dataModels';

export const NewComponent: React.FC<NewComponentProps> = ({
  title,
  items,
  onAction,
}) => {
  // 防御的プログラミング:必ずチェック
  if (!title || !Array.isArray(items)) return null;
  if (items.length === 0) return null;

  return (
    <section className="...">
      <h2>{title}</h2>
      {items.map((item, index) => (
        <div key={index}>{item}</div>
      ))}
    </section>
  );
};

命名規則

種別規則
コンポーネントPascalCaseMediaPlayer.tsx
フックcamelCase + useuseTimeline.ts
イベントハンドラhandle + 動詞handleClick, handleSubmit
定数UPPER_SNAKEMAX_ITEMS

必須パターン

防御的レンダリング

// ✅ 必須
const renderItems = () => {
  if (!Array.isArray(data?.items)) return null;
  if (data.items.length === 0) return <p>項目がありません</p>;
  return data.items.map(...);
};

// ❌ 禁止
data.items.map(...)

Optional Chaining

// ✅ 推奨
const value = obj?.nested?.value ?? 'default';

// ❌ 禁止
const value = obj.nested.value;

スタイリング (Tailwind CSS 4)

// インラインクラス
<div className="bg-gray-900 text-white p-4 rounded-lg">

// 条件付きクラス
<div className={cn(
  "base-class",
  isActive && "active-class",
  variant === 'primary' ? 'primary-style' : 'secondary-style'
)}>

ファイル作成後のチェック

npm run format    # フォーマット
npm run lint      # ESLint
npm run build     # 型チェック

Score

Total Score

50/100

Based on repository quality metrics

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

Reviews

💬

Reviews coming soon