react-hook-builder
БесплатноБез исполняемых скриптовНе проверенCreates custom React hooks for common patterns including data fetching, forms, authentication, local storage, debounce, and more. Use when users request…
от patricio0312rev★ 64 звезды на GitHubОб этом скилле
React Hook Builder
Build production-ready custom React hooks following best practices and TypeScript patterns.
Core Workflow
- Identify the pattern: Determine what logic to encapsulate
- Design the API: Define inputs, outputs, and options
- Add TypeScript types: Full type safety with generics
- Handle edge cases: Loading, errors, cleanup
- Optimize performance: Memoization where needed
- Write tests: Cover all states and scenarios
Hook Naming Conventions
// Always prefix with "use"
useLocalStorage // ✓
useDebounce // ✓
useFetch // ✓
localStorageHook // ✗
fetchData // ✗
Data Fetching Hooks
useFetch
// hooks/useFetch.ts
import { useState, useEffect, useCallback, useRef } from 'react';
interface UseFetchOptions<T> {
immediate?: boolean;
onSuccess?: (data: T) => void;
onError?: (error: Error) => void;
}
interface UseFetchResult<T> {
data: T | null;
error: Error | null;
isLoading: boolean;
isError: boolean;
isSuccess: boolean;
refetch: () => Promise<void>;
}
export function useFetch<T>(
url: string | null,
options: UseFetchOptions<T> = {}
): UseFetchResult<T> {
const { immediate = true, onSuccess, onError } = options;
const [data, setData] = useState<T | null>(null);
const [error, setError] = useState<Error | null>(null);
const [isLoading, setIsLoading] = useState(false);
const abortControllerRef = useRef<AbortController | null>(null);
const fetchData = useCallback(async () => {
if (!url) return;
// Cancel previous request
abortControllerRef.current?.abort();
abortControllerRef.current = new AbortController();
setIsLoading(true);
setError(null);
try {
const response = await fetch(url, {
signal: abortControllerRef.current.signal,
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
setData(result);
onSuccess?.(result);
} catch (err) {
if (err instanceof Error && err.name === 'AbortError') {
return; // Ignore abort errors
}
const error = err instanceof Error ? err : new Error('Unknown error');
setError(error);
onError?.(error);
} finally {
setIsLoading(false);
}
}, [url, onSuccess, onError]);
useEffect(() => {
if (immediate) {
fetchData();
}
return () => {
abortControllerRef.current?.abort();
};
}, [fetchData, immediate]);
return {
data,
error,
isLoading,
isError: !!error,
isSuccess: !!data && !error,
refetch: fetchData,
};
}
// Usage
function UserProfile({ userId }: { userId: string }) {
const { data: user, isLoading, error } = useFetch<User>(
`/api/users/${userId}`
);
if (isLoading) return <Spinner />;
if (error) return <Error message={error.message} />;
return <Profile user={user!} />;
}
useMutation
// hooks/useMutation.ts
import { useState, useCallback } from 'react';
interface UseMutationOptions<TData, TVariables> {
onSuccess?: (data: TData, variables: TVariables) => void;
onError?: (error: Error, variables: TVariables) => void;
onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables) => void;
}
interface UseMutationResult<TData, TVariables> {
data: TData | null;
error: Error | null;
isLoading: boolean;
isError: boolean;
isSuccess: boolean;
mutate: (variables: TVariables) => Promise<TData | undefined>;
reset: () => void;
}
export function useMutation<TData, TVariables>(
mutationFn: (variables: TVariables) => Promise<TData>,
options: UseMutationOptions<TData, TVariables> = {}
): UseMutationResult<TData, TVariables> {
const { onSuccess, onError, onSettled } = options;
const [data, setData] = useState<TData | null>(null);
const [error, setError] = useState<Error | null>(null);
const [isLoading, setIsLoading] = useState(false);
const mutate = useCallback(
async (variables: TVariables) => {
setIsLoading(true);
setError(null);
try {
const result = await mutationFn(variables);
setData(result);
onSuccess?.(result, variables);
onSettled?.(result, null, variables);
return result;
} catch (err) {
const error = err instanceof Error ? err : new Error('Unknown error');
setError(error);
onError?.(error, variables);
onSettled?.(undefined, error, variables);
return undefined;
} finally {
setIsLoading(false);
}
},
[mutationFn, onSuccess, onError, onSettled]
);
const reset = useCallback(() => {
setData(null);
setError(null);
setIsLoading(false);
}, []);
return {
data,
error,
isLoading,
isError: !!error,
isSuccess: !!data && !error,
mutate,
reset,
};
}
// Usage
function CreateUser() {
const { mutate, isL
Установить react-hook-builder в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл react-hook-builder?
Creates custom React hooks for common patterns including data fetching, forms, authentication, local storage, debounce, and more. Use when users request "create custom hook", "React hook for", "useX hook", or "reusable hook".
Как установить скилл react-hook-builder?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл react-hook-builder запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic