UNPKG

1.77 kBTypeScriptView Raw
1export declare type IRef<T extends HTMLElement = HTMLElement> = IRefObject<T> | IRefCallback<T>;
2export interface IRefObject<T extends HTMLElement = HTMLElement> {
3 current: T | null;
4}
5export declare function isRefObject<T extends HTMLElement>(value: IRef<T> | undefined | null): value is IRefObject<T>;
6export declare type IRefCallback<T extends HTMLElement = HTMLElement> = (ref: T | null) => any;
7export declare function isRefCallback<T extends HTMLElement>(value: IRef<T> | undefined | null): value is IRefCallback<T>;
8/**
9 * Assign the given ref to a target, either a React ref object or a callback which takes the ref as its first argument.
10 */
11export declare function setRef<T extends HTMLElement>(refTarget: IRef<T> | undefined | null, ref: T | null): void;
12/** @deprecated use mergeRefs() instead */
13export declare function combineRefs<T extends HTMLElement>(ref1: IRefCallback<T>, ref2: IRefCallback<T>): IRefCallback<T>;
14/**
15 * Utility for merging refs into one singular callback ref.
16 * If using in a functional component, would recomend using `useMemo` to preserve function identity.
17 */
18export declare function mergeRefs<T extends HTMLElement>(...refs: Array<IRef<T> | null>): IRefCallback<T>;
19export declare function getRef<T extends HTMLElement>(ref: T | IRefObject<T> | null): T | null;
20/**
21 * Creates a ref handler which assigns the ref returned by React for a mounted component to a field on the target object.
22 * The target object is usually a component class.
23 *
24 * If provided, it will also update the given `refProp` with the value of the ref.
25 */
26export declare function refHandler<T extends HTMLElement, K extends string>(refTargetParent: {
27 [k in K]: T | null;
28}, refTargetKey: K, refProp?: IRef<T> | undefined | null): IRefCallback<T>;