Javascript react如何识别它';是类组件还是功能组件?

Javascript react如何识别它';是类组件还是功能组件?,javascript,reactjs,class,components,Javascript,Reactjs,Class,Components,我在React应用程序中创建了两个组件,一个是类组件,另一个是功能组件。但是react如何识别它调用的组件是类组件还是功能组件呢 这是面试官提出的问题 但是react如何识别它调用的组件是类组件还是功能组件呢 有关更深入的解释,请检查。React检查组件的isReactComponent标志(位于React.component.prototype)以确定它是类还是函数 您可以在这里详细阅读:一个简单的关键字搜索类?你/面试官到底想问什么? // Who is a class component

我在React应用程序中创建了两个组件,一个是类组件,另一个是功能组件。但是react如何识别它调用的组件是类组件还是功能组件呢

这是面试官提出的问题

但是react如何识别它调用的组件是类组件还是功能组件呢


有关更深入的解释,请检查。

React检查组件的
isReactComponent
标志(位于
React.component.prototype
)以确定它是类还是函数


您可以在这里详细阅读:

一个简单的关键字搜索
?你/面试官到底想问什么?
// Who is a class component and who is a functional component?
ReactDOM.render(
  <>
    <ComponentA />
    <ComponentB />
    {React.createElement(ComponentA)}
    {React.createElement(ComponentB)}
  </>,
  document.getElementById('root')
);
// @ ReactComponent.js
ReactComponent.prototype.isReactComponent = {};

// @ ReactFiber.js
function shouldConstruct(Component: Function) {
  const prototype = Component.prototype;
  return !!(prototype && prototype.isReactComponent);
}