Element() — react Function Reference
Architecture documentation for the Element() function in Element.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD ef0b4074_b67f_ac3e_52bf_c28dc9520498["Element()"] 9930e8cf_03b4_86c0_be04_47b410246b71["Element.js"] ef0b4074_b67f_ac3e_52bf_c28dc9520498 -->|defined in| 9930e8cf_03b4_86c0_be04_47b410246b71 adfb778d_dcdb_5ece_da70_8b8fdc486f96["useChangeActivitySliceAction()"] ef0b4074_b67f_ac3e_52bf_c28dc9520498 -->|calls| adfb778d_dcdb_5ece_da70_8b8fdc486f96 8e17a924_5c80_54a2_af29_cc1a3ea74797["calculateElementOffset()"] ef0b4074_b67f_ac3e_52bf_c28dc9520498 -->|calls| 8e17a924_5c80_54a2_af29_cc1a3ea74797 style ef0b4074_b67f_ac3e_52bf_c28dc9520498 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-devtools-shared/src/devtools/views/Components/Element.js lines 38–252
export default function Element({data, index, style}: Props): React.Node {
const store = useContext(StoreContext);
const {ownerFlatTree, ownerID, inspectedElementID} =
useContext(TreeStateContext);
const dispatch = useContext(TreeDispatcherContext);
const element =
ownerFlatTree !== null
? ownerFlatTree[index]
: store.getElementAtIndex(index);
const [isHovered, setIsHovered] = useState(false);
const errorsAndWarningsSubscription = useMemo(
() => ({
getCurrentValue: () =>
element === null
? {errorCount: 0, warningCount: 0}
: store.getErrorAndWarningCountForElementID(element.id),
subscribe: (callback: Function) => {
store.addListener('mutated', callback);
return () => store.removeListener('mutated', callback);
},
}),
[store, element],
);
const {errorCount, warningCount} = useSubscription<{
errorCount: number,
warningCount: number,
}>(errorsAndWarningsSubscription);
const changeOwnerAction = useChangeOwnerAction();
const changeActivitySliceAction = useChangeActivitySliceAction();
// Handle elements that are removed from the tree while an async render is in progress.
if (element == null) {
console.warn(`<Element> Could not find element at index ${index}`);
// This return needs to happen after hooks, since hooks can't be conditional.
return null;
}
const handleDoubleClick = () => {
startTransition(() => {
if (element.type === ElementTypeActivity) {
changeActivitySliceAction(element.id);
} else {
changeOwnerAction(element.id);
}
});
};
// $FlowFixMe[missing-local-annot]
const handleClick = ({metaKey, button}) => {
if (id !== null && button === 0) {
logEvent({
event_name: 'select-element',
metadata: {source: 'click-element'},
});
dispatch({
type: 'SELECT_ELEMENT_BY_ID',
payload: metaKey ? null : id,
});
}
};
const handleMouseEnter = () => {
setIsHovered(true);
if (id !== null) {
onElementMouseEnter(id);
}
};
const handleMouseLeave = () => {
setIsHovered(false);
};
// $FlowFixMe[missing-local-annot]
const handleKeyDoubleClick = event => {
// Double clicks on key value are used for text selection (if the text has been truncated).
// They should not enter the owners tree view.
Domain
Subdomains
Source
Frequently Asked Questions
What does Element() do?
Element() is a function in the react codebase, defined in packages/react-devtools-shared/src/devtools/views/Components/Element.js.
Where is Element() defined?
Element() is defined in packages/react-devtools-shared/src/devtools/views/Components/Element.js at line 38.
What does Element() call?
Element() calls 2 function(s): calculateElementOffset, useChangeActivitySliceAction.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free