Custom React Hooks
Meelio provides a collection of custom React hooks for common UI patterns and functionality.Hook Location
All hooks are located in:packages/shared/src/hooks/index.ts:
Available Hooks
useDisclosure
useDisclosure
File:
use-disclosure.tsManages the open/close state of UI elements like modals, dropdowns, and drawers.Signature
Parameters
Initial open state of the disclosure
Returns
Current open state
Function to open the element
Function to close the element
Function to toggle the open state
Usage Example
This hook is commonly used throughout Meelio for managing modal dialogs, sheets, and expandable sections.
useDebouncedValue
useDebouncedValue
File:
use-debounced-value.tsDebounces a value to reduce the frequency of updates, useful for search inputs and expensive operations.Signature
Parameters
The value to debounce
Delay in milliseconds before updating the debounced value
Returns
Returns the debounced value that updates after the specified delay.Usage Example
useInterval
useInterval
File:
use-interval.tsDeclarative interval hook that handles cleanup automatically.Signature
Parameters
Function to execute on each interval
Delay in milliseconds between executions. Pass
null to pause the intervalUsage Example
This hook automatically handles cleanup and updates when the callback changes, making it safer than using
setInterval directly.useOscillation
useOscillation
File:
use-oscillation.tsCreates smooth oscillating values for animations, particularly for soundscape volume oscillation.Signature
Parameters
Starting volume value (0-1)
Whether oscillation is active
Returns
Current oscillating volume value
Linear interpolation function for smooth transitions
Usage Example
The hook uses
requestAnimationFrame for smooth 60fps animations and includes randomized frequency and phase for natural-sounding volume changes.useIsMobile
useIsMobile
useDocumentTitle
useDocumentTitle
File: The hook formats the title as:
use-document-title.tsUpdates the browser tab title to reflect timer state.Signature
Parameters
Seconds remaining in current timer stage
Current timer stage (Focus or Break)
Whether the timer is currently running
Usage Example
- Running:
🎯 25:00 - Focusor☕ 5:00 - Break - Paused:
Meelio - focus, calm, & productivity
useConfetti
useConfetti
useCachedSoundUrl
useCachedSoundUrl
useMounted
useMounted
usePrevious
usePrevious
useDockShortcuts
useDockShortcuts
useWallpaperSearch
useWallpaperSearch
useTimer
useTimer
File:
use-timer.tsTimer-specific hook (currently empty placeholder for future timer utilities).This file is currently empty but reserved for timer-specific hook logic.
Hook Patterns
Cleanup Handling
Many hooks handle cleanup automatically:Memoization
Hooks useuseCallback to prevent unnecessary re-renders:
TypeScript Generics
Hooks support generic types for type safety:Creating Custom Hooks
When creating new hooks for Meelio:Next Steps
Component Overview
Learn about component architecture
State Management
Explore Zustand stores