1 | /** Imported from react-native */
|
2 | import type { MutableRefObject } from 'react';
|
3 | /**
|
4 | * This is a helper function for when a component needs to be able to forward a
|
5 | * ref to a child component, but still needs to have access to that component as
|
6 | * part of its implementation.
|
7 | *
|
8 | * Its main use case is in wrappers for native components.
|
9 | *
|
10 | * Usage:
|
11 | *
|
12 | * Class MyView extends React.Component { _nativeRef = null;
|
13 | *
|
14 | * _setNativeRef = setAndForwardRef({
|
15 | * getForwardedRef: () => this.props.forwardedRef,
|
16 | * setLocalRef: ref => {
|
17 | * this._nativeRef = ref;
|
18 | * },
|
19 | * });
|
20 | *
|
21 | * render() {
|
22 | * return <View ref={this._setNativeRef} />;
|
23 | * }
|
24 | *
|
25 | * }
|
26 | *
|
27 | * Const MyViewWithRef = React.forwardRef((props, ref) => ( <MyView {...props}
|
28 | * forwardedRef={ref} /> ));
|
29 | *
|
30 | * Module.exports = MyViewWithRef;
|
31 | */
|
32 | type ForwardedRef<T> = () => MutableRefObject<T> | ((ref: T) => void);
|
33 | declare function setAndForwardRef<T>({ getForwardedRef, setLocalRef, }: {
|
34 | getForwardedRef: ForwardedRef<T>;
|
35 | setLocalRef: (ref: T) => void;
|
36 | }): (ref: T) => void;
|
37 | export default setAndForwardRef;
|
38 | //# sourceMappingURL=setAndForwardRef.d.ts.map |
\ | No newline at end of file |