UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

27 lines 1.11 kB
// https://stackoverflow.com/questions/33199959/how-to-detect-a-react-component-vs-a-react-element import React from 'react'; import { isHTMLElement } from '@douyinfe/semi-foundation/lib/es/utils/dom'; function isClassComponent(component) { return typeof component === 'function' && Boolean(component.prototype.isReactComponent); } function isFunctionalComponent(Component) { return typeof Component === 'function' && // can be various things !(Component.prototype && Component.prototype.isReactComponent // native arrows don't have prototypes ); } function isReactComponent(component) { return isClassComponent(component) || isFunctionalComponent(component); } function isElement(element) { return /*#__PURE__*/React.isValidElement(element); } function isCompositeTypeElement(element) { return isElement(element) && typeof element.type === 'function'; } function isEmptyChildren(children) { return React.Children.count(children) === 0; } export { isClassComponent, isFunctionalComponent, isReactComponent, isElement, // isDOMTypeElement, isHTMLElement, isCompositeTypeElement, isEmptyChildren };