useAuth
Manages user authentication state and provides authentication methods.Parameters
UseAuthOptions
Configuration options for the authentication hook
Return Value
User | null
The currently authenticated user object, or null if not authenticated
boolean
Whether a user is currently authenticated
boolean
Whether authentication state is being loaded
(credentials: LoginCredentials) => Promise<void>
Function to log in a user with email and password
() => Promise<void>
Function to log out the current user
(data: RegisterData) => Promise<void>
Function to register a new user
Example
useForm
Manages form state, validation, and submission with TypeScript support.Parameters
T
required
Initial form values object
UseFormOptions<T>
Form configuration options
Return Value
T
Current form values
ValidationErrors<T>
Validation errors for each field
Record<keyof T, boolean>
Which fields have been interacted with
boolean
Whether form is currently being submitted
(field: keyof T, value: any) => void
Update a field value
(field: keyof T) => void
Mark a field as touched
(e?: React.FormEvent) => Promise<void>
Submit the form
() => void
Reset form to initial values
(field: keyof T, value: any) => void
Programmatically set a field value
Example
useFetch
Data fetching hook with loading, error states, and caching support.Parameters
string
required
The URL to fetch data from
UseFetchOptions<T>
Fetch configuration options
Return Value
T | null
The fetched data
Error | null
Error object if the fetch failed
boolean
Whether data is currently being fetched
boolean
Whether data is being revalidated in the background
() => Promise<void>
Manually trigger a refetch
(data: T) => void
Manually update the cached data
Example
useLocalStorage
Persists state to localStorage with automatic synchronization across tabs.Parameters
string
required
The localStorage key to store the value under
T
required
Initial value if no stored value exists
UseLocalStorageOptions
Storage configuration options
Return Value
T
The current stored value
(value: T | ((prev: T) => T)) => void
Update the stored value
() => void
Remove the value from localStorage
Example
useDebounce
Debounces a value, useful for search inputs and performance optimization.Parameters
T
required
The value to debounce
number
required
Delay in milliseconds before updating the debounced value
Return Value
T
The debounced value that updates after the specified delay
Example
useMediaQuery
Responds to CSS media query changes for responsive design.Parameters
string
required
CSS media query string (e.g., ‘(min-width: 768px)‘)
Return Value
boolean
Whether the media query currently matches