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].
**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].
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.
Podobné prompty
Advanced AI Features - Deep Dive do Pokročilých Funkcí
Komplexní průvodce pokročilými funkcemi AI nástrojů - od extended context a multimodality po tool use, streaming, a fine-tuning. Naučte se využívat plný potenciál moderních AI systémů.
Programování
Zobrazit
Algoritmus optimalizace
Optimalizace algoritmu z O(n²) na O(n log n) nebo lepší.
Programování
Zobrazit
API design s REST best practices
Návrh RESTful API s dokumentací a error handling.
Programování
Zobrazit
CI/CD pipeline setup
Konfigurace GitHub Actions / GitLab CI pipeline s testing a deployment.
Programování
Zobrazit
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ů.