Custom Hooks
Collection of custom React hooks for common functionality across the application.
useClipboard
Utility
Hook for copying text to clipboard with status feedback.
const { copyToClipboard, copyStatus } = useClipboard()
// Usage
copyToClipboard("Text to copy")
// copyStatus: "idle" | "success" | "error"
useKeyPress
Keyboard
Hook for handling keyboard shortcuts and key press events.
useKeyPress("k", () => {
// Callback function
}, {
metaKey: true, // Command/Windows key
ctrlKey: false // Control key
})
Automatically ignores key events in input fields and contenteditable elements.
useIsMobile
Responsive
Hook for detecting mobile viewport (below 768px).
const isMobile = useIsMobile()
// Returns true if viewport width < 768px
useOS
Platform
Hook for detecting the user's operating system.
const os = useOS()
// Returns: "mac" | "other"
useThemeToggle
Theme
Hook for managing theme toggling functionality.
const { toggleTheme, isDarkTheme } = useThemeToggle()
// Toggle between light and dark themes
toggleTheme()
// Check current theme
console.log(isDarkTheme) // true | false
useUpgradeModal
UI
Hook for managing upgrade modal state with URL query parameters.
const { open, close, isOpen, setIsOpen } = useUpgradeModal()
// Open modal and add ?upgrade=true to URL
open()
// Close modal and remove query parameter
close()
Best Practices
- • All hooks are client-side only
- • Use with appropriate error boundaries
- • Consider SSR implications when using browser APIs
- • Follow React hooks rules and conventions