Claude-skill-registry custom-hook
Creates custom React hooks for SideDish. Use when the user asks to create a new hook, extract shared logic into a hook, or refactor component logic into reusable hooks. Includes TypeScript interfaces, memoization patterns, and index.ts export.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/custom-hook" ~/.claude/skills/majiayu000-claude-skill-registry-custom-hook && rm -rf "$T"
manifest:
skills/data/custom-hook/SKILL.mdsource content
Custom Hook Skill
When to Use
- Creating a new reusable hook (e.g., "create a hook for X")
- Extracting repeated logic from components
- Building hooks for form state, API calls, or UI interactions
Quick Start
1. File Location & Naming
src/hooks/useHookName.ts # 파일명: use + PascalCase
2. Required Structure
/** * [훅 이름] 훅 * * [목적 설명] * [사용 위치 설명] */ import { useState, useCallback } from 'react' import { toast } from 'sonner' // 1. Options 인터페이스 (선택적 설정) export interface UseHookNameOptions { initialValue?: string onError?: (error: string) => void onChange?: (value: string) => void } // 2. Return 인터페이스 (JSDoc 주석 권장) export interface UseHookNameReturn { /** 현재 값 */ value: string /** 값 변경 핸들러 */ setValue: (value: string) => void /** 상태 초기화 */ reset: () => void /** 유효성 여부 */ isValid: boolean } // 3. 훅 구현 (named export) export function useHookName(options: UseHookNameOptions = {}): UseHookNameReturn { const { initialValue = '', onError, onChange } = options const [value, setValueInternal] = useState(initialValue) // useCallback으로 메모이제이션 const handleError = useCallback((message: string) => { onError ? onError(message) : toast.error(message) }, [onError]) const setValue = useCallback((newValue: string) => { setValueInternal(newValue) onChange?.(newValue) }, [onChange]) const reset = useCallback(() => { setValueInternal(initialValue) }, [initialValue]) return { value, setValue, reset, isValid: value.length > 0, } } // 4. default export export default useHookName
3. Update index.ts
// src/hooks/index.ts에 추가 export { useHookName } from './useHookName' export type { UseHookNameOptions, UseHookNameReturn } from './useHookName'
Checklist
- 파일명이
+ PascalCase 형식인가?use - JSDoc 주석이 상단에 있는가?
-
와Options
인터페이스가 export 되었는가?Return - 콜백 함수들이
으로 감싸져 있는가?useCallback - 에러 처리가
또는toast.error
콜백을 사용하는가?onError -
에 export가 추가되었는가?index.ts
Project Integration
// form-constants.ts 사용 시 import { PROJECT_CONSTRAINTS, FORM_ERROR_MESSAGES } from '@/lib/form-constants' // API 클라이언트 사용 시 import { ApiError } from '@/lib/api-client'
For advanced patterns (API hooks, form integration, compound hooks), see reference.md.