lndsld

Home > @lndsld/react-hooks

react-hooks package

Library with reusable React hooks

Functions

Function Description
useChange(observer, observable) Subscribe to value changes (like componentDidUpdate from class components)
useDebouncedCallback(callback, delay) Apply debounce to callbackIf callback wasn’t invoked during specified time, last call will be invoked
useDomRect(ref) Subscribe to changes of element’s DOMRect
useEvent(callback) Get stable reference to event handler
useForwardedRef(forwardedRef) Make proxy for ForwardedRef
useInterval(callback, initialDelay) Let callback automatically run with specified time interval
usePointerEvent(eventType, handler, options) Subscribe to pointer events
usePointerEvent(eventType, handler, options)  
usePointerEvent(eventType, handler, options)  
usePortalRoot() Create root for React portal
usePrevious(value) Get value from previous render
usePrevious(value, initialValue)  
usePropState(prop) Create state from propThis state will by synced with prop
useResize(ref, options) Subscribe to element’s resize
useScroll(handler, options) Subscribe to scroll events
useThrottledCallback(callback, timeout) Throttle callbackReduce frequency of callback invocations
useToggle(value) Create boolean toggle
useUserSelect(value, options) Sets user-select CSS property
useWindowSize() Subscribe to changes of browser window’s width and height

Interfaces

Interface Description
IntervalAPI Declaration of API to control interval
ToggleAdditionalAPI Declaration of additional API for toggle
UsePointerEventOptions Configuration options for usePointerEvent hook
UseResizeOptions Configuration options for useResize hook
UseScrollOptions Configuration options for useScroll hook
UseUserSelectOptions Configuration options for useUserSelect hook

Variables

Variable Description
useClickOutside Subscribe to clicks outside of element

Type Aliases

Type Alias Description
ChangeCallback Callback, invoked on value change
EventCallback Event handler declaration
MouseEventType Type of mouse event
NativeEventHandler Native Event handler
NativeMouseEventHandler Native MouseEvent handler
NativePointerEventHandler Native PointerEvent handler
NativeTouchEventHandler Native TouchEvent handler
PointerEventType Type of pointer event
TouchEventType Type of touch event
UserSelectType Available values for user-select property