/*! * ======================================================================== * @rzl-zone/core-react * ------------------------------------------------------------------------ * Version: `0.0.14` * Author: `Rizalvin Dwiky ` * Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/core-react` * ======================================================================== */ import { Ref, RefCallback } from "react"; /** ------------------------------------------------------------------- * * ***Merges multiple React refs into a single ref callback, * allowing them to be assigned simultaneously.*** * -------------------------------------------------------------------- * * This utility enables safe composition of refs when multiple components, * hooks, or consumers need access to the same underlying DOM element * or component instance. * * It supports both: * - **Callback refs** * - **Mutable object refs** (`RefObject`) * * - **Behavior:** * - Invokes all function refs with the provided value * - Assigns the value to `.current` for object refs * - Safely ignores `undefined` refs * - Preserves invocation order from left to right * * This is especially useful in **React** when combining forwarded refs * with internal refs. * * @typeParam T - The type of the ref value (e.g. `HTMLDivElement`). * @param refs - A list of refs to merge. Each ref may be a callback, * a ref object, or `undefined`. * * @returns A single `RefCallback` that updates all provided refs. * * @example * ```tsx * const localRef = useRef(null); * * function Component(props: { ref?: Ref }) { * return ( *
* ); * } * ``` */ declare function mergeRefs(...refs: (Ref | undefined)[]): RefCallback; export { mergeRefs };