Hooks
This page documents public hooks exported by src/hooks/index.ts.
Public hook API
useClickOutside
Detect pointer interactions outside a target element.
const ref = useClickOutside(() => setOpen(false))
return <div ref={ref}>...</div>useIntersectionObserver
Observe viewport intersection and optionally freeze once visible.
const [ref, entry, isVisible] = useIntersectionObserver({ threshold: 0.25 })useKeyPress
Track whether a key (or set of keys) is pressed.
const isEscapePressed = useKeyPress("Escape")useCopyToClipboard
Copy text with success/error state tracking.
const { copy, copied, error } = useCopyToClipboard()useAsync
Run async workflows with idle/pending/success/error state.
const { execute, data, error, isLoading, status } = useAsync(fetchUsers)Important note
src/hooks includes additional local hooks (useDebounce, useLocalStorage, useMediaQuery, useToggle) that are currently not exported via src/hooks/index.ts.
Best practices
- Keep async functions passed to
useAsyncstable withuseCallbackwhen needed. - Use
useClickOutsideonly in browser contexts (not during SSR-only execution paths). - Pair
useKeyPresswith clear keyboard affordances in UI and docs.