UNPKG

@kopexa/react-utils

Version:

A set of utilities for react on client side

29 lines (26 loc) 1 kB
import { Ref, RefCallback, ReactNode } from 'react'; /** * A function that merges React refs into one. * Supports both functions and ref objects created using createRef() and useRef(). * * Usage: * ```tsx * <div ref={mergeRefs(ref1, ref2, ref3)} /> * ``` * * @param {(Ref<T> | undefined)[]} inputRefs Array of refs * @returns {Ref<T> | RefCallback<T>} Merged refs */ declare function mergeRefs<T>(...inputRefs: (Ref<T> | undefined)[]): Ref<T> | RefCallback<T>; /** * This is a helper function that is used when a component supports `asChild` * using the `Slot` component but its implementation contains nested DOM elements. * * Using it ensures if a consumer uses the `asChild` prop, the elements are in * correct order in the DOM, adopting the intended consumer `children`. */ declare function getSubtree(options: { asChild: boolean | undefined; children: ReactNode; }, content: ReactNode | ((children: ReactNode) => ReactNode)): ReactNode; export { getSubtree, mergeRefs };