MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / findDOMNode

Function findDOMNode

lib/utils/test/render.ts:113–146  ·  view source on GitHub ↗
(instance: unknown)

Source from the content-addressed store, hash-verified

111 * in which case the first DOM node rendered into the test container is returned.
112 */
113export function findDOMNode(instance: unknown): HTMLElement | Text | null {
114 if (instance == null) {
115 return null;
116 } else if (instance instanceof Node) {
117 return instance as HTMLElement | Text;
118 }
119
120 const fiber = (instance as { _reactInternals?: Fiber })._reactInternals;
121 if (!fiber && instance === lastRendered && mountNode) {
122 return mountNode.firstChild as HTMLElement | Text | null;
123 }
124 if (!fiber) {
125 throw Error(
126 "findDOMNode() expects a mounted class component instance or the value returned by the most recent render() call"
127 );
128 }
129
130 // Depth-first search for the first host (DOM) node
131 const stack: Fiber[] = fiber.child ? [fiber.child] : [];
132 while (stack.length > 0) {
133 const current = stack.pop()!;
134 if (current.stateNode instanceof Node) {
135 return current.stateNode as HTMLElement | Text;
136 }
137 if (current.sibling) {
138 stack.push(current.sibling);
139 }
140 if (current.child) {
141 stack.push(current.child);
142 }
143 }
144
145 return null;
146}

Callers 14

List.test.tsxFile · 0.90
simulateScrollFunction · 0.90
Masonry.test.tsxFile · 0.90
renderWithChildrenFunction · 0.90
Table.test.tsxFile · 0.90
renderHelperFunction · 0.90
renderWithChildFunction · 0.90
MultiGrid.test.tsxFile · 0.90
getGridsFunction · 0.90
simulateScrollFunction · 0.90
getScrollPositionFunction · 0.90

Calls

no outgoing calls

Tested by 8

simulateScrollFunction · 0.72
renderWithChildrenFunction · 0.72
renderHelperFunction · 0.72
renderWithChildFunction · 0.72
getGridsFunction · 0.72
simulateScrollFunction · 0.72
getScrollPositionFunction · 0.72
getStylesFunction · 0.72