Hooks
The library exports a set of hooks used internally by components and available for consumer applications. Each hook is small, focused, SSR-safe, and tree-shakeable.
Available hooks
Section titled “Available hooks”useClickOutside— fire a callback when a click lands outside one or more refsuseClipboard— copy text to the clipboard with timeout-driven feedback stateuseControlledState— manage the controlled / uncontrolled state patternuseDisclosure—{ isOpen, open, close, toggle }for overlays and revealed surfacesuseEventCallback— stable callback identity that always invokes the latest versionuseFocusTrap— trap keyboard focus within a containeruseHotkey— bind a single keyboard combo to a callback, with platform-aware Cmd/Ctrl mappinguseIsMounted— stable getter for whether the component is still mounteduseKeyboard— read the live keyboard state via contextuseMergedRef— merge multiple refs into a single callback refuseResizeObserver— observe element size changes with SSR-safe cleanupuseTheme— read the current theme at runtime — values, variant, andgetToken/getVarhelpers
Importing
Section titled “Importing”All hooks are exported from the package root:
import { useClickOutside, useClipboard, useControlledState, useDisclosure, useFocusTrap, useHotkey, useMergedRef, useResizeObserver, useTheme,} from 'entangle-ui';Conventions
Section titled “Conventions”Every hook in this library follows the same conventions:
- SSR-safe: hooks that touch browser globals (
ResizeObserver,document,navigator, etc.) check for their existence and silently no-op on the server. - Stable callback identity: callbacks passed to hooks do not need to be memoized by the consumer. The hook wraps them in a ref so the underlying observer / effect does not re-subscribe on every render.
enabledtoggles, not unmounts: when a hook accepts anenabledflag, toggling it safely attaches / detaches its effect without unmounting the component.- Dev-only warnings: misuse warnings (controlled / uncontrolled switches, etc.) only fire in development. Production builds are silent.