Agent skill
add-hook
Create a shared React hook in packages/shared/hooks/
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/add-hook-corbanb-x4-mono
SKILL.md
Add Hook Skill
Create a shared React hook in packages/shared/hooks/ for use across web, mobile, and desktop apps.
Arguments
The user describes the hook. If unclear, ask for:
- Hook name (camelCase with
useprefix, e.g.,useDebounce,useLocalStorage) - What it returns (state shape)
- Whether it needs a
.native.tsvariant for React Native
File Location
- Hook:
packages/shared/hooks/{hookName}.ts(or.tsxif JSX needed) - Native variant:
packages/shared/hooks/{hookName}.native.ts(optional) - Test:
packages/shared/hooks/{hookName}.test.ts(co-located) - Export:
packages/shared/hooks/index.ts
Hook Template
Reference: packages/shared/hooks/useAuth.ts
/**
* Brief description of what the hook does.
*
* @example
* ```tsx
* const { value, setValue } = useMyHook('key');
* ```
*/
export interface UseMyHookOptions {
/** Option description */
initialValue?: string;
}
export interface UseMyHookReturn {
/** Return value description */
value: string | null;
/** Whether the hook is loading */
isLoading: boolean;
/** Update the value */
setValue: (value: string) => void;
}
export function useMyHook(options: UseMyHookOptions = {}): UseMyHookReturn {
const { initialValue = null } = options;
// Hook implementation using React hooks
// ...
return {
value,
isLoading,
setValue,
};
}
Native Variant (optional)
If the hook needs different behavior on React Native, create a .native.ts file:
// packages/shared/hooks/useMyHook.native.ts
// React Native bundlers (Metro) automatically resolve .native.ts over .ts
export function useMyHook(options: UseMyHookOptions = {}): UseMyHookReturn {
// React Native-specific implementation
}
Export from Index
Add to packages/shared/hooks/index.ts:
export { useMyHook } from './useMyHook';
export type { UseMyHookOptions, UseMyHookReturn } from './useMyHook';
Test Template
import { describe, test, expect } from 'bun:test';
import { renderHook, act } from '@testing-library/react';
import { useMyHook } from './useMyHook';
describe('useMyHook', () => {
test('returns initial state', () => {
const { result } = renderHook(() => useMyHook());
expect(result.current.value).toBeNull();
expect(result.current.isLoading).toBe(false);
});
test('updates value', () => {
const { result } = renderHook(() => useMyHook());
act(() => {
result.current.setValue('new value');
});
expect(result.current.value).toBe('new value');
});
});
Conventions
- Naming: Always prefix with
use(camelCase) - Types: Export both options and return type interfaces
- Dependencies: Hooks in
packages/shared/must NOT import fromapps/* - JSX config: If the hook file uses
.tsx, ensurepackages/shared/tsconfig.jsonhas"jsx": "react-jsx" - File extension: Use
.tsunless JSX is needed, then.tsx
Workflow
- Create hook file at
packages/shared/hooks/{hookName}.ts - Define options and return type interfaces
- Implement the hook
- Export from
packages/shared/hooks/index.ts - Create
.native.tsvariant if needed - Create co-located test file
- Run
bun turbo type-checkto verify
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?