jpskill.com
🛠️ 開発・MCP コミュニティ

web-framework-react

ReactというJavaScriptライブラリを用いて、ウェブアプリケーションの画面を部品のように組み合わせて構築したり、便利な機能を利用したり、効率的な開発手法を適用したりするSkill。

📜 元の英語説明(参考)

Component architecture, hooks, patterns

🇯🇵 日本人クリエイター向け解説

一言でいうと

ReactというJavaScriptライブラリを用いて、ウェブアプリケーションの画面を部品のように組み合わせて構築したり、便利な機能を利用したり、効率的な開発手法を適用したりするSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o web-framework-react.zip https://jpskill.com/download/10283.zip && unzip -o web-framework-react.zip && rm web-framework-react.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10283.zip -OutFile "$d\web-framework-react.zip"; Expand-Archive "$d\web-framework-react.zip" -DestinationPath $d -Force; ri "$d\web-framework-react.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して web-framework-react.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → web-framework-react フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

React コンポーネント

クイックガイド: 階層化されたコンポーネント (Primitives -> Components -> Patterns -> Templates)。React 19: ref をプロパティとして直接渡す ( forwardRef は不要)。スタイリングの柔軟性のために className プロパティを公開。フォームには useActionState 、即時フィードバックには useOptimistic 、条件付きの Promise/Context の読み取りには use() を使用。Ref コールバックはクリーンアップ関数を返すことができます。


<critical_requirements>

重要: この Skill を使用する前に

すべてのコードは CLAUDE.md のプロジェクト規約に従う必要があります (kebab-case、名前付きエクスポート、インポート順、import type、名前付き定数)

(React 19 では ref を通常のプロパティとして渡す必要があります - forwardRef は非推奨です)

(すべての再利用可能なコンポーネントでカスタマイズのために className プロパティを公開する必要があります)

(保留/エラー状態のフォーム送信には useActionState を使用する必要があります)

( <form> 内の子コンポーネントから useFormStatus を呼び出す必要があります。フォームをレンダリングするコンポーネント内ではありません)

</critical_requirements>


自動検出: React 19、コンポーネント、フック、use()、useActionState、useFormStatus、useOptimistic、Actions、prop としての ref、ref クリーンアップ、forwardRef の移行、コンポーネントのバリアント、エラー境界

使用する場合:

  • 型安全なプロパティを持つ React コンポーネントを構築する場合
  • forwardRef から React 19 の ref-as-prop に移行する場合
  • React 19 Actions API を使用してフォーム送信を処理する場合
  • 再利用可能なロジックのためのカスタムフックを作成する場合
  • リトライ付きのエラー境界を実装する場合

使用しない場合:

  • バリアントのない単純な使い捨てコンポーネント (バリアントの抽象化はスキップ)
  • インタラクティブ性のない静的コンテンツ

カバーされる主要なパターン:

  • コンポーネントアーキテクチャの階層とバリアントプロパティ
  • React 19 の prop としての ref (forwardRef を置き換えます)
  • React 19 フック: use()useActionStateuseFormStatususeOptimistic
  • Ref コールバックのクリーンアップ関数
  • リトライとカスタムフォールバックを備えたエラー境界
  • カスタムフック (ページネーション、デバウンス、localStorage)
  • イベントハンドラーの命名規則

<philosophy>

Philosophy

React コンポーネントは、低レベルのプリミティブから高レベルのテンプレートまでの階層化されたアーキテクチャに従います。コンポーネントは、構成可能で型安全であり、必要なカスタマイズポイント (className、refs) を公開する必要があります。コンポーネントに複数のバリアントディメンションがある場合にのみバリアントの抽象化を使用し、過剰なエンジニアリングを避けてください。React はスタイリングに依存しません -- className プロパティを介してスタイルを適用します。

React 19 の変更点: forwardRef は非推奨です -- ref を通常のプロパティとして直接渡します。新しいフック (use()useActionStateuseFormStatususeOptimistic) は、Actions API を使用したデータフェッチとフォーム処理を簡素化します。Ref コールバックはクリーンアップ関数を返すことができるため、個別の useEffect クリーンアップは不要になります。

</philosophy>


<patterns>

コアパターン

パターン 1: コンポーネントアーキテクチャの階層

コンポーネントは階層化された階層で編成されています。

  1. Primitives (src/primitives/) - 低レベルのビルディングブロック (スケルトン)
  2. Components (src/components/) - 再利用可能な UI (ボタン、スイッチ、セレクト)
  3. Patterns (src/patterns/) - 構成されたパターン (機能、ナビゲーション)
  4. Templates (src/templates/) - ページレイアウト (フレーム)
// React 19: ref を通常のプロパティとして、forwardRef は不要
export type ButtonProps = React.ComponentProps<"button"> & {
  variant?: "default" | "ghost" | "link";
  size?: "default" | "large" | "icon";
  asChild?: boolean;
  ref?: React.Ref<HTMLButtonElement>;
};

export function Button({ variant = "default", size = "default", className, ref, ...props }: ButtonProps) {
  return <button className={className} data-variant={variant} data-size={size} ref={ref} {...props} />;
}

良い理由: prop としての ref は forwardRef のボイラープレートを排除し、className は外部スタイリングを可能にし、data-attributes はバリアントの CSS セレクターを可能にします

完全なコンポーネントの例と良い/悪い比較については、examples/core.md を参照してください。


パターン 2: コンポーネントバリアントプロパティ

2 つ以上の視覚的なディメンション (バリアント、サイズ) を持つコンポーネントは、TypeScript ユニオンを介して型安全なバリアントプロパティを公開する必要があります。任意のスタイリングソリューションがそれらをターゲットにできるように、data-* 属性を使用します。

export type AlertVariant = "info" | "warning" | "error" | "success";

export function Alert({ variant = "info", className, ref, ...props }: AlertProps) {
  return <div ref={ref} className={className} data-variant={variant} {...props} />;
}

使用しない場合: 単一の視覚スタイルを持つコンポーネント -- バリアントの抽象化はスキップします。

バリアントプロパティの良い/悪い例については、examples/core.md を参照してください。


パターン 3: イベントハンドラーの命名

  • 内部ハンドラーの handle プレフィックス: handleSubmithandleNameChange
  • コールバックプロパティの on プレフィックス: onClickonSubmit
  • イベントを明示的に型指定: FormEvent<HTMLFormElement>ChangeEvent<HTMLInputElement>
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
  e.preventDefault();
};

const handleNameChange = (e: ChangeEvent<HTMLInputElement>) => {
  setName(e.target.value);
};

完全なイベントハンドラーの例については、examples/core.md を参照してください。


パターン 4: カスタムフック

再利用可能なロジックを use プレフィックス規則に従ってカスタムフックに抽出します。

  • usePagination - ページネーションの状態とナビゲーション
  • useDebounce - 検索入力のデバウンス値
  • useLocalStorage - SSR セーフティを備えた型安全な localStorage 永続化

完全な実装については、examples/hooks.md を参照してください。


パターン 5: リトライ付きのエラー境界

エラー境界はレンダリングエラーをキャッチし、リトライ機能を提供します。ルートだけでなく、機能セクションの周りに配置します。

// 主要なインターフェース -- カスタムフォールバックとエラーコールバックを受け入れます
interface Props {
  children: ReactNode;
  fallback?: (error: Error, reset: () => void) => ReactNode;
  onError?: (error: Error, errorInfo: ErrorInfo) => void;
}

制限事項: エラー境界は、イベントハンドラーエラー、非同期エラー、または SSR エラーをキャッチしません -- それらには try/catch を使用します。

[examples/ (原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

React Components

Quick Guide: Tiered components (Primitives -> Components -> Patterns -> Templates). React 19: pass ref as a prop directly (no forwardRef needed). Expose className prop for styling flexibility. Use useActionState for forms, useOptimistic for instant feedback, use() for conditional promise/context reading. Ref callbacks can return cleanup functions.


<critical_requirements>

CRITICAL: Before Using This Skill

All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering, import type, named constants)

(You MUST pass ref as a regular prop in React 19 - forwardRef is deprecated)

(You MUST expose className prop on ALL reusable components for customization)

(You MUST use useActionState for form submissions with pending/error state)

(You MUST call useFormStatus from a child component inside <form>, NOT in the component that renders the form)

</critical_requirements>


Auto-detection: React 19, components, hooks, use(), useActionState, useFormStatus, useOptimistic, Actions, ref as prop, ref cleanup, forwardRef migration, component variants, error boundary

When to use:

  • Building React components with type-safe props
  • Migrating from forwardRef to React 19 ref-as-prop
  • Handling form submissions with React 19 Actions API
  • Creating custom hooks for reusable logic
  • Implementing error boundaries with retry

When NOT to use:

  • Simple one-off components without variants (skip variant abstractions)
  • Static content without interactivity

Key patterns covered:

  • Component architecture tiers and variant props
  • React 19 ref as prop (replaces forwardRef)
  • React 19 hooks: use(), useActionState, useFormStatus, useOptimistic
  • Ref callback cleanup functions
  • Error boundaries with retry and custom fallbacks
  • Custom hooks (pagination, debounce, localStorage)
  • Event handler naming conventions

<philosophy>

Philosophy

React components follow a tiered architecture from low-level primitives to high-level templates. Components should be composable, type-safe, and expose necessary customization points (className, refs). Use variant abstractions only when components have multiple variant dimensions to avoid over-engineering. React is styling-agnostic -- apply styles via the className prop.

React 19 Changes: forwardRef is deprecated -- pass ref as a regular prop directly. New hooks (use(), useActionState, useFormStatus, useOptimistic) simplify data fetching and form handling with the Actions API. Ref callbacks can return cleanup functions, eliminating the need for separate useEffect cleanup.

</philosophy>


<patterns>

Core Patterns

Pattern 1: Component Architecture Tiers

Components are organized in a tiered hierarchy:

  1. Primitives (src/primitives/) - Low-level building blocks (skeleton)
  2. Components (src/components/) - Reusable UI (button, switch, select)
  3. Patterns (src/patterns/) - Composed patterns (feature, navigation)
  4. Templates (src/templates/) - Page layouts (frame)
// React 19: ref as a regular prop, no forwardRef needed
export type ButtonProps = React.ComponentProps<"button"> & {
  variant?: "default" | "ghost" | "link";
  size?: "default" | "large" | "icon";
  asChild?: boolean;
  ref?: React.Ref<HTMLButtonElement>;
};

export function Button({ variant = "default", size = "default", className, ref, ...props }: ButtonProps) {
  return <button className={className} data-variant={variant} data-size={size} ref={ref} {...props} />;
}

Why good: ref as regular prop eliminates forwardRef boilerplate, className enables external styling, data-attributes enable CSS selectors for variants

See examples/core.md for complete component examples with good/bad comparisons.


Pattern 2: Component Variant Props

Components with 2+ visual dimensions (variant, size) should expose type-safe variant props via TypeScript unions. Use data-* attributes so any styling solution can target them.

export type AlertVariant = "info" | "warning" | "error" | "success";

export function Alert({ variant = "info", className, ref, ...props }: AlertProps) {
  return <div ref={ref} className={className} data-variant={variant} {...props} />;
}

When not to use: Components with a single visual style -- skip variant abstraction.

See examples/core.md for variant props with good/bad examples.


Pattern 3: Event Handler Naming

  • handle prefix for internal handlers: handleSubmit, handleNameChange
  • on prefix for callback props: onClick, onSubmit
  • Type events explicitly: FormEvent<HTMLFormElement>, ChangeEvent<HTMLInputElement>
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
  e.preventDefault();
};

const handleNameChange = (e: ChangeEvent<HTMLInputElement>) => {
  setName(e.target.value);
};

See examples/core.md for full event handler examples.


Pattern 4: Custom Hooks

Extract reusable logic into custom hooks following the use prefix convention.

  • usePagination - Pagination state and navigation
  • useDebounce - Debounce values for search inputs
  • useLocalStorage - Type-safe localStorage persistence with SSR safety

See examples/hooks.md for complete implementations.


Pattern 5: Error Boundaries with Retry

Error boundaries catch render errors and provide retry capability. Place them around feature sections, not just the root.

// Key interface -- accepts custom fallback and error callback
interface Props {
  children: ReactNode;
  fallback?: (error: Error, reset: () => void) => ReactNode;
  onError?: (error: Error, errorInfo: ErrorInfo) => void;
}

Limitation: Error boundaries do not catch event handler errors, async errors, or SSR errors -- use try/catch for those.

See examples/error-boundaries.md for full implementation.


Pattern 6: useActionState for Form Submissions

Skip if your framework provides its own server-side form handling (Server Actions) — use that instead.

Use useActionState for form submissions with automatic pending state and error handling. Replaces manual useState for loading/error.

import { useActionState } from "react";

async function updateProfile(prevState: string | null, formData: FormData) {
  try {
    await saveProfile({ name: formData.get("name") as string });
    return null;
  } catch {
    return "Failed to save profile";
  }
}

export function ProfileForm() {
  const [error, submitAction, isPending] = useActionState(updateProfile, null);

  return (
    <form action={submitAction}>
      <input type="text" name="name" disabled={isPending} />
      <button type="submit" disabled={isPending}>
        {isPending ? "Saving..." : "Save"}
      </button>
      {error && <p role="alert">{error}</p>}
    </form>
  );
}

Why good: hook manages pending and error state automatically, form action works with progressive enhancement, no manual useState for loading/error

See examples/react-19-hooks.md for extended examples with success state.


Pattern 7: useFormStatus for Submit Buttons

useFormStatus reads parent form's pending state without prop drilling. Must be called from a child component inside the <form>.

import { useFormStatus } from "react-dom";

function SubmitButton() {
  const { pending } = useFormStatus();
  return (
    <button type="submit" disabled={pending}>
      {pending ? "Submitting..." : "Submit"}
    </button>
  );
}

Gotcha: Calling useFormStatus in the component that renders <form> returns pending: false always -- it must be a descendant component.

See examples/react-19-hooks.md for reusable submit button patterns.


Pattern 8: useOptimistic for Instant UI Feedback

Show immediate UI updates while async operations complete. State automatically reverts if the request fails.

import { useOptimistic, startTransition } from "react";

const [optimisticItems, addOptimistic] = useOptimistic(
  items,
  (state, update: Item) => [...state, { ...update, pending: true }],
);

// In handler -- setter MUST be called inside startTransition:
startTransition(async () => {
  addOptimistic(newItem);
  await saveItem(newItem);
});

See examples/react-19-hooks.md for todo list and chat examples.


Pattern 9: use() Hook for Promises and Context

use() reads promises and context conditionally in render -- unlike useContext, it can be called after early returns.

import { use, Suspense } from "react";

function Comments({ commentsPromise }: { commentsPromise: Promise<Comment[]> }) {
  const comments = use(commentsPromise); // Suspends until resolved
  return <ul>{comments.map((c) => <li key={c.id}>{c.text}</li>)}</ul>;
}

// Wrap in Suspense boundary
<Suspense fallback={<p>Loading...</p>}>
  <Comments commentsPromise={fetchComments()} />
</Suspense>

Gotcha: use() cannot be called in try-catch blocks -- use Error Boundaries for rejected promise handling.

See examples/react-19-hooks.md for conditional context reading.


Pattern 10: Ref Callback Cleanup Functions

React 19 ref callbacks can return cleanup functions, replacing the need for separate useEffect cleanup.

function VideoPlayer({ src }: { src: string }) {
  return (
    <video
      ref={(video) => {
        if (!video) return;
        video.play();
        return () => {
          video.pause();
          video.currentTime = 0;
        };
      }}
      src={src}
    />
  );
}

Why good: cleanup runs automatically on unmount, no separate useEffect needed, simpler than useRef + useEffect combination

Note: With ref cleanup functions, TypeScript rejects non-null/undefined return values from ref callbacks. The callback is no longer called with null on unmount -- the cleanup function handles that.

See examples/react-19-hooks.md for IntersectionObserver cleanup example.

</patterns>


Detailed Resources:


<red_flags>

RED FLAGS

High Priority Issues:

  • Using forwardRef in React 19 -- deprecated, pass ref as a regular prop
  • Calling useFormStatus in the component that renders <form> -- will always return pending: false
  • Using useState for form loading/error when useActionState exists -- unnecessary boilerplate
  • Not exposing className prop on reusable components -- prevents external styling
  • Calling use() inside try-catch blocks -- use Error Boundaries instead

Medium Priority Issues:

  • Adding variant abstractions for components without multiple variant dimensions
  • Using useCallback on every handler regardless of child memoization (premature optimization)
  • Wrapping ref callbacks in useCallback when the React Compiler handles memoization automatically
  • Generic event handler names (click, change) instead of descriptive names (handleNameChange)

Gotchas & Edge Cases:

  • Ref cleanup functions: TypeScript rejects non-null/undefined returns from ref callbacks -- use the cleanup pattern explicitly
  • useOptimistic state reverts automatically on failure -- no manual rollback needed
  • use() can be called conditionally (after early returns), unlike useContext
  • Error boundaries do not catch event handler errors, async errors, or SSR errors
  • useCallback without memoized children adds overhead without benefit
  • SSR requires typeof window !== "undefined" before accessing browser APIs

</red_flags>


<critical_reminders>

CRITICAL REMINDERS

All code must follow project conventions in CLAUDE.md

(You MUST pass ref as a regular prop in React 19 - forwardRef is deprecated)

(You MUST expose className prop on ALL reusable components for customization)

(You MUST use useActionState for form submissions with pending/error state)

(You MUST call useFormStatus from a child component inside <form>, NOT in the component that renders the form)

Failure to follow these rules will break component composition, form state management, and styling flexibility.

</critical_reminders>