getComponentOrHookLike() — react Function Reference
Architecture documentation for the getComponentOrHookLike() function in Program.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 2bfe28c2_c730_2f65_86db_f782c4b5a3e5["getComponentOrHookLike()"] 9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|defined in| 9aa4477d_960b_1ea1_b6d9_36076aaa70bd 37c561cb_7b67_6332_ee68_b69aaf917134["getReactFunctionType()"] 37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 1351f300_d3f0_8ef1_7520_1bc143225b34["getFunctionName()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| 1351f300_d3f0_8ef1_7520_1bc143225b34 e14c5b91_7099_c5ae_9e58_90fa1685a39e["isComponentName()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| e14c5b91_7099_c5ae_9e58_90fa1685a39e d2202a9e_2022_7233_6674_e1ea8713692c["callsHooksOrCreatesJsx()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| d2202a9e_2022_7233_6674_e1ea8713692c 6020b327_3c33_4f61_7c23_7f5e35e56457["isValidComponentParams()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| 6020b327_3c33_4f61_7c23_7f5e35e56457 2148cf00_8996_be31_be94_747fe87bb264["returnsNonNode()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| 2148cf00_8996_be31_be94_747fe87bb264 9793c5f8_5898_48eb_13f7_d8191c7098b3["isHook()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| 9793c5f8_5898_48eb_13f7_d8191c7098b3 8e26b3bb_a1d7_155c_c8b6_2082b5792efb["isForwardRefCallback()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| 8e26b3bb_a1d7_155c_c8b6_2082b5792efb ee42cd13_5e0a_8266_50bb_9daa20e7a0b2["isMemoCallback()"] 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 -->|calls| ee42cd13_5e0a_8266_50bb_9daa20e7a0b2 style 2bfe28c2_c730_2f65_86db_f782c4b5a3e5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts lines 1183–1213
function getComponentOrHookLike(
node: NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>,
hookPattern: string | null,
): ReactFunctionType | null {
const functionName = getFunctionName(node);
// Check if the name is component or hook like:
if (functionName !== null && isComponentName(functionName)) {
let isComponent =
callsHooksOrCreatesJsx(node, hookPattern) &&
isValidComponentParams(node.get('params')) &&
!returnsNonNode(node);
return isComponent ? 'Component' : null;
} else if (functionName !== null && isHook(functionName, hookPattern)) {
// Hooks have hook invocations or JSX, but can take any # of arguments
return callsHooksOrCreatesJsx(node, hookPattern) ? 'Hook' : null;
}
/*
* Otherwise for function or arrow function expressions, check if they
* appear as the argument to React.forwardRef() or React.memo():
*/
if (node.isFunctionExpression() || node.isArrowFunctionExpression()) {
if (isForwardRefCallback(node) || isMemoCallback(node)) {
// As an added check we also look for hook invocations or JSX
return callsHooksOrCreatesJsx(node, hookPattern) ? 'Component' : null;
}
}
return null;
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does getComponentOrHookLike() do?
getComponentOrHookLike() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts.
Where is getComponentOrHookLike() defined?
getComponentOrHookLike() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts at line 1183.
What does getComponentOrHookLike() call?
getComponentOrHookLike() calls 8 function(s): callsHooksOrCreatesJsx, getFunctionName, isComponentName, isForwardRefCallback, isHook, isMemoCallback, isValidComponentParams, returnsNonNode.
What calls getComponentOrHookLike()?
getComponentOrHookLike() is called by 1 function(s): getReactFunctionType.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free