UNPKG

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