UNPKG

839 BTypeScriptView Raw
1/// <reference types="react" />
2declare type CallbackRef<T> = (ref: T | null) => void;
3declare type Ref<T> = React.MutableRefObject<T> | CallbackRef<T>;
4export declare function mergeRefs<T>(refA?: Ref<T> | null, refB?: Ref<T> | null): (value: T | null) => void;
5/**
6 * Create and returns a single callback ref composed from two other Refs.
7 *
8 * ```tsx
9 * const Button = React.forwardRef((props, ref) => {
10 * const [element, attachRef] = useCallbackRef<HTMLButtonElement>();
11 * const mergedRef = useMergedRefs(ref, attachRef);
12 *
13 * return <button ref={mergedRef} {...props}/>
14 * })
15 * ```
16 *
17 * @param refA A Callback or mutable Ref
18 * @param refB A Callback or mutable Ref
19 * @category refs
20 */
21declare function useMergedRefs<T>(refA?: Ref<T> | null, refB?: Ref<T> | null): (value: T | null) => void;
22export default useMergedRefs;