← スキル一覧に戻る

react-hooks
by HoangNguyen0403
react-hooksは、other分野における実用的なスキルです。複雑な課題への対応力を強化し、業務効率と成果の質を改善します。
⭐ 111🍴 40📅 2026年1月23日
SKILL.md
name: React Hooks description: Best practices for React Hooks usage and custom hook creation. metadata: labels: [react, hooks, custom-hooks, useeffect] triggers: files: ['/*.tsx', '/*.jsx'] keywords: [useEffect, useCallback, useMemo, useRef, custom hook]
React Hooks
Priority: P1 (OPERATIONAL)
Effective usage of React Hooks.
Implementation Guidelines
- Rules: Top-level only. Only in React functions.
useEffect: Sync with external systems ONLY. Cleanup required.useRef: Mutable state without re-renders (DOM, timers, tracking).useMemo/Callback: Measure first. Use for stable refs or heavy computation.- Dependencies: Exhaustive deps always. Fix logic, don't disable linter.
- Custom Hooks: Extract shared logic. Prefix
use*. - Refs as Escape Hatch: Access imperative APIs (focus, scroll).
- Stability: Use
useLatestpattern (ref) for event handlers to avoid dependency changes. - Concurrency:
useTransition/useDeferredValuefor non-blocking UI updates. - Initialization: Lazy state
useState(() => expensive()).
Anti-Patterns
- No Effects for Data Flow: Derive state in render.
- No Missing Deps: Causes stale closures.
- No Complex Effects: Split into multiple simple effects.
- No Oversubscription: Check
why-did-you-render.
Code
// Custom Hook
function useWindowSize() {
const [size, setSize] = useState({ w: 0, h: 0 });
useEffect(() => {
function handleResize() {
setSize({ w: window.innerWidth, h: window.innerHeight });
}
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []); // Empty = mount only
return size;
}
// Lazy Init
const [state, setState] = useState(() => computeExpensiveValue());
Reference & Examples
スコア
総合スコア
85/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
✓説明文
100文字以上の説明がある
+10
✓人気
GitHub Stars 100以上
+5
✓最近の活動
3ヶ月以内に更新
+5
✓フォーク
10回以上フォークされている
+5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
レビュー
💬
レビュー機能は近日公開予定です

