Programování Pokročilý Claude

React custom hook s TypeScript

Vytvoření reusable React custom hook s proper typing.

Prompt text

Délka: Střední
Vytvoř React custom hook pro [USE CASE].

**Functionality:**
[CO HOOK DĚLÁ - např. data fetching, form handling, local storage]

**Requirements:**
1. TypeScript s proper generics
2. Error handling
3. Loading states
4. Cleanup (useEffect)
5. Memoization (useMemo, useCallback)
6. Dependencies správně

**API:**
```typescript
const { data, loading, error, refetch } = use[HookName]<T>(params);
```

**Include:**
- Hook implementation
- Type definitions
- Usage examples (min 2)
- Unit tests
- JSDoc documentation

**Avoid:**
- React Hook rules violations
- Memory leaks
- Unnecessary re-renders

React version: [VERSION].
Interaktivní tvůrce

Příklad použití

Vstup:

Vytvoř useFetch hook pro data fetching s auto refetch, error handling, caching. Generic pro any data type. React 18 + TypeScript 5.

Výstup:

Complete custom hook: useFetch<T>(url, options) with TypeScript generics, returns { data: T | null, loading, error, refetch }, implementation with useEffect (cleanup on unmount), useState for state management, useCallback for refetch memoization, error boundaries support, abort controller for request cancellation, cache with useRef + optional cache key, dependency array correctly set. Types: FetchOptions, FetchResult<T>. Usage examples: fetching users (User[]), single user (User). Tests: loading states, success, error, refetch, cleanup. JSDoc with @example tags.

Kde použít tento prompt?

Najděte vhodné AI nástroje pro použití tohoto promptu a maximalizujte jeho efektivitu.

Objevte další AI prompty

Prozkoumejte naši sbírku Programování promptů a najděte ty, které vám pomohou dosáhnout lepších výsledků.