UNPKG

@storm-stack/hooks

Version:

A collection of React hooks used by Storm Software in various client libraries and applications.

22 lines (21 loc) 480 B
import { isFunction } from "@storm-stack/types/type-checks/is-function"; import { useCallback } from "react"; export function setRef(ref, value) { if (ref) { if (isFunction(ref)) { ref(value); } else { ref.current = value; } } } export function composeRefs(...refs) { return (node) => { for (const ref of refs) { setRef(ref, node); } }; } export function useComposedRefs(...refs) { return useCallback(composeRefs(...refs), refs); }