Overview
Openlane UI provides a collection of custom React hooks for common patterns including lifecycle management, device detection, input debouncing, window events, and file uploads.Lifecycle Hooks
useMounted
Detects when a component has mounted on the client side. Location:packages/ui/hooks/use-mounted.ts:3
true once the component has mounted
Use Case: Prevent hydration mismatches in SSR applications
Example:
Device Detection
useIsTouchDevice
Detects if the user is on a touch-capable device. Location:packages/ui/hooks/use-is-touch-device.ts:5
true if the device supports touch input
Features:
- Checks multiple touch detection methods
- Updates on window resize
- Client-side only hook
Input Hooks
useDebounce
Debounces a value to reduce update frequency. Location:packages/ui/hooks/use-debounce.ts:3
value- The value to debouncedelay- Delay in milliseconds (default: 500)
- Search input handling
- API call rate limiting
- Form validation
Window Event Hooks
useOnWindowResize
Executes a callback when the window is resized. Location:packages/ui/lib/windowResize.tsx:3
handler- Callback function to execute on resize
- Automatically cleans up event listeners
- Executes handler immediately on mount
- Optimized with proper dependency tracking
File Upload Hooks
useUploadFile
Manages file upload state and operations with progress tracking. Location:packages/ui/hooks/use-upload-file.ts:17
isUploading- Whether a file is currently uploadingprogress- Upload progress (0-100)uploadedFile- The uploaded file data after completionuploadFile- Function to trigger file uploaduploadingFile- The file currently being uploaded
- Progress tracking
- Error handling with toast notifications
- Mock upload fallback for unauthenticated users
- Automatic cleanup on unmount
useUploadThing
Low-level hook for UploadThing integration. Location:packages/ui/hooks/use-upload-file.ts:93