UNPKG

@ozen-ui/kit

Version:

React component library

20 lines (19 loc) 777 B
import { isValidElement } from 'react'; import { isFunction } from '../isFunction'; import { isPlainObject } from '../object'; export var isNodeWithDisplayName = function (node, displayName) { var isValid = isValidElement(node); if (!isValid) { return false; } if (!isPlainObject(node.type) && !isFunction(node.type)) { return false; } var isEqualByTypeDisplayName = 'displayName' in node.type && node.type.displayName === displayName; var isEqualByRenderDisplayName = 'render' in node.type && node.type.render && isFunction(node.type.render) && 'displayName' in node.type.render && node.type.render.displayName === displayName; return isEqualByTypeDisplayName || !!isEqualByRenderDisplayName; };