import * as React from 'react' ; import { useDefaultProps } from './useDefaultProps' ; export function createComponent < Props > ( Component , config ? ) { const Comp = ( props , ref ) => { const { props : newProps } = useDefaultProps ( props , config ) ; return React . createElement ( Component , { ... newProps , elementRef : ref } , props ?. children ) ; } ; let ForwardedComponent = React . forwardRef ( Comp ) ; if ( config . shouldMemo ) { ForwardedComponent = React . memo ( ForwardedComponent ) ; } return Object . assign ( ForwardedComponent , config . attach ) ; }