Custom Hooks
The core package provides a comprehensive collection of custom React hooks for common use cases.Storage Hooks
useLocalStorageState
Persist state inlocalStorage with automatic serialization and deserialization.
Location: @workspace/core/hooks/use-local-storage-state
localStorage key to store the value
Default value if no stored value exists
Custom serialization function (defaults to JSON.stringify)
Custom deserialization function (defaults to JSON.parse)
[T, (value: T) => void] - State value and setter function
useSessionStorageState
Persist state insessionStorage with automatic serialization.
Location: @workspace/core/hooks/use-session-storage-state
useLocalStorageState
Returns: [T, (value: T) => void] - State value and setter function
Media & Browser Hooks
useMediaQuery
React to CSS media query changes with automatic updates on resize. Location:@workspace/core/hooks/use-media-query
CSS media query string to match against
boolean - Whether the media query matches
useCopyToClipboard
Copy text to clipboard with status feedback. Location:@workspace/core/hooks/use-copy-to-clipboard
Duration in ms before
isCopied resets to falseisCopied:boolean- Whether text was recently copiedcopyToClipboard:(value: string) => void- Function to copy text
useColorMode
Manage color theme with localStorage persistence and system preference detection. Location:@workspace/core/hooks/use-color-mode
CSS selector for the target element
HTML attribute to modify (‘class’ or custom attribute)
Initial color mode
localStorage key for persistence
Disable CSS transitions during mode switch
[colorMode, setColorMode] - Current mode and setter
Timer Hooks
useInterval
Declarative interval with automatic cleanup and pause/resume. Location:@workspace/core/hooks/use-interval
Callback function to execute at each interval
Interval duration in milliseconds. Set to null/undefined to pause.
Execute callback immediately on mount/delay change
() => void - Function to manually clear the interval
useTimeout
Declarative timeout with automatic cleanup. Location:@workspace/core/hooks/use-timeout
Callback function to execute after timeout
Timeout duration in milliseconds. Set to null/undefined to cancel.
() => void - Function to manually clear the timeout
useRafInterval
RequestAnimationFrame-based interval for smooth animations. Location:@workspace/core/hooks/use-raf-interval
Returns: () => void - Function to clear the interval
useRafTimeout
RequestAnimationFrame-based timeout for smooth animations. Location:@workspace/core/hooks/use-raf-timeout
Returns: () => void - Function to clear the timeout
State Management Hooks
useControllableValue
Manage both controlled and uncontrolled component states. Location:@workspace/core/hooks/use-controllable-value
Component props potentially containing value/onChange
Default value for uncontrolled mode
Name of the value prop
Name of the change handler prop
[T, (value: T) => void] - Current value and setter
useResetState
State with a reset function to return to initial value. Location:@workspace/core/hooks/use-reset-state
[state, setState, resetState]
useDynamicList
Manage dynamic lists with unique keys for each item. Location:@workspace/core/hooks/use-dynamic-list
list:T[]- Current listinsert:(index: number, item: T) => void- Insert at positionmerge:(index: number, items: T[]) => void- Merge multiple itemsreplace:(index: number, item: T) => void- Replace itemremove:(index: number) => void- Remove itemgetKey:(index: number) => number- Get unique keygetIndex:(key: number) => number- Get index from keymove:(oldIndex: number, newIndex: number) => void- Move itempush:(item: T) => void- Add to endpop:() => void- Remove from endunshift:(item: T) => void- Add to startshift:() => void- Remove from startresetList:(newList: T[]) => void- Reset entire list
useHistoryTravel
Time-travel state management with undo/redo. Location:@workspace/core/hooks/use-history-travel
Lifecycle Hooks
useMount
Execute a function once when component mounts. Location:@workspace/core/hooks/use-mount
Function to execute on mount
useUpdateEffect
Run effect on updates only, not on mount. Location:@workspace/core/hooks/use-update-effect
useUpdateLayoutEffect
Run layout effect on updates only. Location:@workspace/core/hooks/use-update-layout-effect
useUpdate
Force component re-render. Location:@workspace/core/hooks/use-update
() => void - Function to trigger re-render
Utility Hooks
useLatest
Get the latest value without closure issues. Location:@workspace/core/hooks/use-latest
Value to keep up-to-date
React.MutableRefObject<T> - Ref containing latest value
useMemoizedFn
Memoize function with stable reference. Location:@workspace/core/hooks/use-memoized-fn
Function to memoize
useMultipleRefs
Combine multiple refs into one. Location:@workspace/core/hooks/use-multiple-refs
useSelections
Manage multi-select state. Location:@workspace/core/hooks/use-selections
useAutoScroll
Auto-scroll to bottom when content changes. Location:@workspace/core/hooks/use-auto-scroll
Hook Factories
createUseStorageState
Factory for creating custom storage hooks. Location:@workspace/core/hooks/create-use-storage-state
createUpdateEffect
Factory for creating custom update effect hooks. Location:@workspace/core/hooks/create-update-effect