Skip to content

Hooks

Complete reference for every public hook export in @kamod-ch/hooks.

Alphabetical overview#

  • useBoolean — Boolean state with setTrue, setFalse, set, and toggle helpers.
  • useControllableValue — Unifies controlled and uncontrolled component state.
  • useCounter — Number state with increment, decrement, set, and reset actions.
  • useDynamicList — Mutable-feeling list helpers for insert, remove, move, and reset.
  • useEventEmitter — Creates a small event bus shared through hook subscriptions.
  • useEventTarget — Builds value/onChange pairs from event-like targets.
  • useGetState — State plus a getter that always returns the latest value.
  • useHistoryTravel — Undo and redo history for a value.
  • useMap — Map state with set, remove, and reset helpers.
  • useRafState — State updates batched to the next animation frame.
  • useReactive — Reactive proxy object that re-renders on mutation.
  • useResetState — State with a reset function for the initial value.
  • useSafeState — State setter that no-ops after unmount.
  • useSelections — Multi-select helpers for a collection.
  • useSet — Set state with add, remove, and reset helpers.
  • useSetState — Object state merging like class setState.
  • useToggle — Toggles between two values.
  • useAsyncEffect — Runs an async effect and supports async cleanup.
  • useCreation — Creates a memoized value with a stable instance until deps change.
  • useDebounce — Returns a debounced copy of a changing value.
  • useDebounceEffect — Runs an effect after dependency changes settle.
  • useDebounceFn — Returns a debounced function with run, cancel, and flush.
  • useDeepCompareEffect — Runs an effect when deep-equal dependencies actually change.
  • useDeepCompareLayoutEffect — Layout-effect variant of useDeepCompareEffect.
  • useLatest — Returns a ref that always points at the latest value.
  • useMemoizedFn — Stable callback reference that still sees fresh state.
  • usePrevious — Stores the previous value from the last render.
  • useThrottle — Returns a throttled copy of a changing value.
  • useThrottleEffect — Runs an effect at throttled intervals for dependency changes.
  • useThrottleFn — Returns a throttled function wrapper.
  • useTrackedEffect — Shows which dependency indexes changed between runs.
  • useUpdate — Returns a function that forces a re-render.
  • useUpdateEffect — Skips the first effect run and only reacts to updates.
  • useUpdateLayoutEffect — Layout-effect variant of useUpdateEffect.
  • useWhyDidYouUpdate — Logs prop differences to the console for debugging.
  • useIsomorphicLayoutEffect — useLayoutEffect in the browser and useEffect on the server.
  • useMount — Runs logic once when the component mounts.
  • useUnmount — Runs cleanup logic when the component unmounts.
  • useUnmountedRef — Mutable ref that flips to true after unmount.
  • useClickAway — Calls a handler when interaction happens outside the target.
  • useDrag — Makes an element draggable and writes payload data to dataTransfer.
  • useDrop — Reads drag, drop, and paste data from a target element.
  • useEventListener — Attaches DOM event listeners with cleanup.
  • useFocusWithin — Reports whether focus is currently inside a subtree.
  • useFullscreen — Controls fullscreen mode for a specific target element.
  • useHover — Tracks whether a target is hovered.
  • useKeyPress — Runs a handler when matching keys are pressed.
  • useLongPress — Recognizes long-press gestures with delay control.
  • useMouse — Tracks pointer coordinates relative to the page and an element.
  • useMutationObserver — Subscribes to DOM mutations on a target.
  • useScroll — Reads scroll position from an element or document.
  • useSize — Reads width and height from ResizeObserver.
  • useTextSelection — Tracks current text selection and bounding box.
  • useCookieState — Persists a string state value in a browser cookie.
  • useDocumentVisibility — Tracks document.visibilityState.
  • useExternal — Loads external JS or CSS and reports the loading status.
  • useFavicon — Sets the current document favicon.
  • useInViewport — Tracks visibility with IntersectionObserver.
  • useInfiniteScroll — Loads the next result chunk when a scroll target reaches its edge.
  • useLocalStorageState — State synchronized with localStorage.
  • useNetwork — Reports online state and network information when available.
  • useResponsive — Responsive breakpoint flags based on window width.
  • useSessionStorageState — State synchronized with sessionStorage.
  • useTheme — Tracks light, dark, and system theme modes.
  • useTitle — Sets document.title and can restore the previous value.
  • useUrlState — Synchronizes state with the URL query string via History API.
  • useVirtualList — Virtualizes a long list inside a scroll container.
  • useWebSocket — WebSocket connection state with reconnect and send helpers.
  • useAntdTable — Table request state with pagination, sorters, filters, and search helpers.
  • useFusionTable — Fusion table helper with pagination and search state.
  • useLockFn — Prevents overlapping async function executions.
  • usePagination — Pagination state built on top of useRequest.
  • useRequest — Async request lifecycle with loading, data, error, refresh, and plugins.
  • useCountDown — Counts down to a target time and returns formatted remaining parts.
  • useInterval — Declarative interval tied to component lifetime.
  • useRafInterval — Interval scheduled through requestAnimationFrame.
  • useRafTimeout — Timeout scheduled through requestAnimationFrame.
  • useTimeout — Declarative timeout tied to component lifetime.

State#

  • useBoolean — Boolean state with setTrue, setFalse, set, and toggle helpers.
  • useControllableValue — Unifies controlled and uncontrolled component state.
  • useCounter — Number state with increment, decrement, set, and reset actions.
  • useDynamicList — Mutable-feeling list helpers for insert, remove, move, and reset.
  • useEventEmitter — Creates a small event bus shared through hook subscriptions.
  • useEventTarget — Builds value/onChange pairs from event-like targets.
  • useGetState — State plus a getter that always returns the latest value.
  • useHistoryTravel — Undo and redo history for a value.
  • useMap — Map state with set, remove, and reset helpers.
  • useRafState — State updates batched to the next animation frame.
  • useReactive — Reactive proxy object that re-renders on mutation.
  • useResetState — State with a reset function for the initial value.
  • useSafeState — State setter that no-ops after unmount.
  • useSelections — Multi-select helpers for a collection.
  • useSet — Set state with add, remove, and reset helpers.
  • useSetState — Object state merging like class setState.
  • useToggle — Toggles between two values.

Effects#

Lifecycle#

DOM and events#

  • useClickAway — Calls a handler when interaction happens outside the target.
  • useDrag — Makes an element draggable and writes payload data to dataTransfer.
  • useDrop — Reads drag, drop, and paste data from a target element.
  • useEventListener — Attaches DOM event listeners with cleanup.
  • useFocusWithin — Reports whether focus is currently inside a subtree.
  • useFullscreen — Controls fullscreen mode for a specific target element.
  • useHover — Tracks whether a target is hovered.
  • useKeyPress — Runs a handler when matching keys are pressed.
  • useLongPress — Recognizes long-press gestures with delay control.
  • useMouse — Tracks pointer coordinates relative to the page and an element.
  • useMutationObserver — Subscribes to DOM mutations on a target.
  • useScroll — Reads scroll position from an element or document.
  • useSize — Reads width and height from ResizeObserver.
  • useTextSelection — Tracks current text selection and bounding box.

Browser APIs#

Async and requests#

  • useAntdTable — Table request state with pagination, sorters, filters, and search helpers.
  • useFusionTable — Fusion table helper with pagination and search state.
  • useLockFn — Prevents overlapping async function executions.
  • usePagination — Pagination state built on top of useRequest.
  • useRequest — Async request lifecycle with loading, data, error, refresh, and plugins.

Timing#

  • useCountDown — Counts down to a target time and returns formatted remaining parts.
  • useInterval — Declarative interval tied to component lifetime.
  • useRafInterval — Interval scheduled through requestAnimationFrame.
  • useRafTimeout — Timeout scheduled through requestAnimationFrame.
  • useTimeout — Declarative timeout tied to component lifetime.

Utilities#