@sinchsmb/ui-kit
Version:
UI kit for SinchSMB frontend
14 lines (11 loc) • 455 B
text/typescript
import { MemoExoticComponent, ReactElement, ReactNode, isValidElement } from 'react';
/** Return `true` if given child is give React element */
export function isElement<P>(
child: Exclude<ReactNode, boolean | null | undefined>,
element: ((props: P) => JSX.Element | null) | MemoExoticComponent<(props: P) => JSX.Element | null>,
): child is ReactElement<P> {
if (!isValidElement(child)) {
return false;
}
return child.type === element;
}