MCPcopy
hub / github.com/react/react / findNodeHandle

Function findNodeHandle

packages/react-native-renderer/src/ReactNativePublicCompat.js:91–160  ·  view source on GitHub ↗
(componentOrHandle: any)

Source from the content-addressed store, hash-verified

89}
90
91export function findNodeHandle(componentOrHandle: any): ?number {
92 if (__DEV__) {
93 const owner = currentOwner;
94 if (owner !== null && isRendering && owner.stateNode !== null) {
95 if (!owner.stateNode._warnedAboutRefsInRender) {
96 console.error(
97 '%s is accessing findNodeHandle inside its render(). ' +
98 'render() should be a pure function of props and state. It should ' +
99 'never access something that requires stale data from the previous ' +
100 'render, such as refs. Move this logic to componentDidMount and ' +
101 'componentDidUpdate instead.',
102 getComponentNameFromType(owner.type) || 'A component',
103 );
104 }
105
106 owner.stateNode._warnedAboutRefsInRender = true;
107 }
108 }
109
110 if (componentOrHandle == null) {
111 return null;
112 }
113
114 if (typeof componentOrHandle === 'number') {
115 // Already a node handle
116 return componentOrHandle;
117 }
118
119 // For compatibility with legacy renderer instances
120 if (componentOrHandle._nativeTag) {
121 return componentOrHandle._nativeTag;
122 }
123
124 // For compatibility with Fabric instances
125 if (
126 componentOrHandle.canonical != null &&
127 componentOrHandle.canonical.nativeTag != null
128 ) {
129 return componentOrHandle.canonical.nativeTag;
130 }
131
132 // For compatibility with Fabric public instances
133 const nativeTag = getNativeTagFromPublicInstance(componentOrHandle);
134 if (nativeTag) {
135 return nativeTag;
136 }
137
138 let hostInstance;
139 if (__DEV__) {
140 hostInstance = findHostInstanceWithWarning(
141 componentOrHandle,
142 'findNodeHandle',
143 );
144 } else {
145 hostInstance = findHostInstance(componentOrHandle);
146 }
147
148 if (hostInstance == null) {

Callers 2

getHostNodeFunction · 0.90

Calls 5

findHostInstanceFunction · 0.90
getComponentNameFromTypeFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected