スキル一覧に戻る
hydershah

react-patterns

by hydershah

Advance Appliance - Next.js 15 + Payload CMS website with 3 design themes

0🍴 0📅 2026年1月25日
GitHubで見るManusで実行

SKILL.md


name: react-patterns description: React best practices, hooks patterns, and component architecture. Use when building React components or debugging React issues. (project) allowed-tools: Read, Grep, Glob, Edit, Write, Bash

React Patterns & Best Practices

Component Structure

  • Use functional components with hooks
  • Keep components small and focused (single responsibility)
  • Extract custom hooks for reusable logic
  • Co-locate related files (component, styles, tests)

State Management

Local State

const [value, setValue] = useState(initialValue);

Complex State

const [state, dispatch] = useReducer(reducer, initialState);

Global State Options

  • React Context for simple global state (auth, theme)
  • Zustand for lightweight state management
  • Jotai for atomic state
  • Redux Toolkit for complex applications

Hooks Patterns

Custom Hooks

function useDebounce<T>(value: T, delay: number): T {
  const [debouncedValue, setDebouncedValue] = useState(value);

  useEffect(() => {
    const timer = setTimeout(() => setDebouncedValue(value), delay);
    return () => clearTimeout(timer);
  }, [value, delay]);

  return debouncedValue;
}

Data Fetching

function useFetch<T>(url: string) {
  const [data, setData] = useState<T | null>(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<Error | null>(null);

  useEffect(() => {
    fetch(url)
      .then(res => res.json())
      .then(setData)
      .catch(setError)
      .finally(() => setLoading(false));
  }, [url]);

  return { data, loading, error };
}

Performance Optimization

Memoization

// Memoize expensive calculations
const expensiveValue = useMemo(() => computeExpensive(a, b), [a, b]);

// Memoize callbacks
const handleClick = useCallback(() => doSomething(id), [id]);

// Memoize components
const MemoizedComponent = React.memo(MyComponent);

Lazy Loading

const LazyComponent = React.lazy(() => import('./HeavyComponent'));

<Suspense fallback={<Loading />}>
  <LazyComponent />
</Suspense>

Component Patterns

Compound Components

<Select>
  <Select.Option value="a">Option A</Select.Option>
  <Select.Option value="b">Option B</Select.Option>
</Select>

Render Props

<DataFetcher url="/api/data">
  {({ data, loading }) => loading ? <Spinner /> : <List items={data} />}
</DataFetcher>

Higher-Order Components

const withAuth = (Component) => (props) => {
  const { user } = useAuth();
  if (!user) return <Redirect to="/login" />;
  return <Component {...props} user={user} />;
};

スコア

総合スコア

40/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

レビュー

💬

レビュー機能は近日公開予定です