Tree() — react Function Reference
Architecture documentation for the Tree() function in Tree.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 8903e7f2_b245_fcae_5413_05a60dcaa5e4["Tree()"] 80ad5569_a221_98e5_daec_ede1bea33ee0["Tree.js"] 8903e7f2_b245_fcae_5413_05a60dcaa5e4 -->|defined in| 80ad5569_a221_98e5_daec_ede1bea33ee0 8e17a924_5c80_54a2_af29_cc1a3ea74797["calculateElementOffset()"] 8903e7f2_b245_fcae_5413_05a60dcaa5e4 -->|calls| 8e17a924_5c80_54a2_af29_cc1a3ea74797 adfb778d_dcdb_5ece_da70_8b8fdc486f96["useChangeActivitySliceAction()"] 8903e7f2_b245_fcae_5413_05a60dcaa5e4 -->|calls| adfb778d_dcdb_5ece_da70_8b8fdc486f96 078bd51f_6be5_7560_d1ad_d8f38bacfb55["calculateInitialScrollOffset()"] 8903e7f2_b245_fcae_5413_05a60dcaa5e4 -->|calls| 078bd51f_6be5_7560_d1ad_d8f38bacfb55 style 8903e7f2_b245_fcae_5413_05a60dcaa5e4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-devtools-shared/src/devtools/views/Components/Tree.js lines 76–548
export default function Tree(): React.Node {
const dispatch = useContext(TreeDispatcherContext);
const {
activityID,
numElements,
ownerID,
searchIndex,
searchResults,
inspectedElementID,
inspectedElementIndex,
} = useContext(TreeStateContext);
const bridge = useContext(BridgeContext);
const store = useContext(StoreContext);
const {hideSettings} = useContext(OptionsContext);
const {lineHeight} = useContext(SettingsContext);
const [isNavigatingWithKeyboard, setIsNavigatingWithKeyboard] =
useState(false);
const {highlightHostInstance, clearHighlightHostInstance} =
useHighlightHostInstance();
const [treeFocused, setTreeFocused] = useState<boolean>(false);
const componentsPanelVisible = useExtensionComponentsPanelVisibility(bridge);
const treeRef = useRef<HTMLDivElement | null>(null);
const focusTargetRef = useRef<HTMLDivElement | null>(null);
const listDOMElementRef = useRef<Element | null>(null);
const setListDOMElementRef = useCallback((listDOMElement: Element) => {
listDOMElementRef.current = listDOMElement;
// Controls the initial horizontal offset of the Tree if the element was pre-selected. For example, via Elements panel in browser DevTools.
// Initial vertical offset is controlled via initialScrollOffset prop of the FixedSizeList component.
if (
!componentsPanelVisible ||
inspectedElementIndex == null ||
listDOMElement == null
) {
return;
}
const element = store.getElementAtIndex(inspectedElementIndex);
if (element == null) {
return;
}
const viewportLeft = listDOMElement.scrollLeft;
const viewportRight = viewportLeft + listDOMElement.clientWidth;
const elementLeft = calculateElementOffset(element.depth);
// Because of virtualization, this element might not be rendered yet; we can't look up its width.
// Assuming that it may take up to the half of the viewport.
const elementRight = elementLeft + listDOMElement.clientWidth / 2;
const isElementFullyVisible =
elementLeft >= viewportLeft && elementRight <= viewportRight;
if (!isElementFullyVisible) {
const horizontalDelta =
Math.min(0, elementLeft - viewportLeft) +
Math.max(0, elementRight - viewportRight);
// $FlowExpectedError[incompatible-call] Flow doesn't support instant as an option for behavior.
listDOMElement.scrollBy({
left: horizontalDelta,
behavior: 'instant',
});
}
}, []);
useEffect(() => {
if (!componentsPanelVisible || inspectedElementIndex == null) {
return;
}
const listDOMElement = listDOMElementRef.current;
if (listDOMElement == null) {
return;
}
const viewportHeight = listDOMElement.clientHeight;
const viewportLeft = listDOMElement.scrollLeft;
const viewportRight = viewportLeft + listDOMElement.clientWidth;
const viewportTop = listDOMElement.scrollTop;
Domain
Subdomains
Source
Frequently Asked Questions
What does Tree() do?
Tree() is a function in the react codebase, defined in packages/react-devtools-shared/src/devtools/views/Components/Tree.js.
Where is Tree() defined?
Tree() is defined in packages/react-devtools-shared/src/devtools/views/Components/Tree.js at line 76.
What does Tree() call?
Tree() calls 3 function(s): calculateElementOffset, calculateInitialScrollOffset, useChangeActivitySliceAction.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free