mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-18 13:53:11 +00:00
41 lines
903 B
TypeScript
41 lines
903 B
TypeScript
import {
|
|
ComponentClass,
|
|
ElementType,
|
|
FunctionComponent,
|
|
PropsWithChildren,
|
|
ReactText,
|
|
} from 'react';
|
|
|
|
export interface IReactElementSubset<TProps = {}> {
|
|
props: PropsWithChildren<TProps>;
|
|
type: ElementType<TProps>;
|
|
}
|
|
|
|
export type ReactElementSubsetWithPrimitive =
|
|
| IReactElementSubset
|
|
| ReactText
|
|
| ReactElementSubsetWithPrimitive[]
|
|
| null
|
|
| undefined;
|
|
|
|
export function isFunctionalComponent(
|
|
eleType: ElementType
|
|
): eleType is FunctionComponent {
|
|
return (
|
|
typeof eleType === 'function' && // can be various things
|
|
!(
|
|
(eleType.prototype && eleType.prototype.isReactComponent) // native arrows don't have prototypes // special property
|
|
)
|
|
);
|
|
}
|
|
|
|
export function isClassComponent(
|
|
eleType: ElementType
|
|
): eleType is ComponentClass {
|
|
return !!(
|
|
typeof eleType === 'function' &&
|
|
eleType.prototype &&
|
|
eleType.prototype.isReactComponent
|
|
);
|
|
}
|