Frontend
Custom Hooks
Reusable React hooks for state management, API calls, and common patterns
Overview
The application provides a set of custom hooks for common patterns. All hooks are exported from @/hooks.
useAuth
Manages authentication state and provides login/logout methods.
Auth State
| Property | Type | Description |
|---|---|---|
user | User | null | Current authenticated user |
isAuthenticated | boolean | Whether user is logged in |
isLoading | boolean | Loading state |
error | string | null | Error message |
Auth Methods
| Method | Parameters | Description |
|---|---|---|
login | LoginRequest | Login with email/password |
signup | SignupRequest | Register new user |
logout | - | Log out current user |
forgotPassword | ForgotPasswordRequest | Request password reset |
resetPassword | ResetPasswordRequest | Reset password with token |
clearError | - | Clear error state |
refreshSession | - | Refresh access token |
useApi
Generic hook for API calls with loading, error, caching, and retry support.
Options
| Option | Type | Default | Description |
|---|---|---|---|
immediate | boolean | false | Execute on mount |
cacheKey | string | - | Key for caching results |
cacheDuration | number | 300000 | Cache TTL in ms (5 min) |
retries | number | 0 | Number of retry attempts |
retryDelay | number | 1000 | Delay between retries in ms |
Cache Utilities
useForm
Lightweight form management with validation.
Built-in Validators
useDebounce
Debounces a value for search inputs and API calls.
useMediaQuery
Responds to CSS media queries.
useWindowSize
Tracks window dimensions.
useThrottledWindowSize
Throttled version for performance-sensitive use cases.
useScrollDirection
Detects scroll direction for hiding/showing headers.
useAsyncError
Throws errors to error boundaries from async code.