import * as React from 'react'; import { useDefaultProps } from './useDefaultProps'; export function createComponent( Component: React.FunctionComponent, config?: { attach?: { displayName?: string; useProps: (props?: Partial, config?: { disableCSSProps?: Array; themeKey?: string }) => any; }; defaultProps?: Partial; themeKey?: string; shouldMemo?: boolean; } ) { const Comp = (props: Props, ref) => { const { props: newProps } = useDefaultProps(props, config); // @ts-ignore return React.createElement(Component, { ...newProps, elementRef: ref }, props?.children); }; let ForwardedComponent = React.forwardRef(Comp); if (config.shouldMemo) { // @ts-ignore ForwardedComponent = React.memo(ForwardedComponent); } return Object.assign(ForwardedComponent, config.attach); }