Class components are inherently states, but with the advent of React hooks, functional components are no longer called stateless because they can also be composed.
The special property isReactComponent exists in React.Component since React.Component 0.14. This allows you to determine whether a component is a component of a class.
function isFunctionalComponent(Component) { return ( typeof Component === 'function' // can be various things && !( Component.prototype // native arrows don't have prototypes && Component.prototype.isReactComponent // special property ) ); } function isClassComponent(Component) { return !!( typeof Component === 'function' && Component.prototype && Component.prototype.isReactComponent ); }
Similar checks are performed in the React code base.
Since components can be various things, such as a Context Provider or a Consumer , isFunctionalComponent(Component) may not be equal to !isClassComponent(Component) .
Estus flask
source share