Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 557x 6432x 6432x 557x | import * as React from 'react'; import _get from 'lodash/get'; import { useDefaultProps } from './useDefaultProps'; export function createComponent<P>( Component: React.FunctionComponent<P>, config?: { attach?: { useProps: (props?: Partial<P>, config?: { themeKey?: string }) => any; }; defaultProps?: Partial<P>; themeKey?: string; } ) { const ForwardedComponent = React.forwardRef((props: P, ref) => { const { props: newProps } = useDefaultProps(props, config); // @ts-ignore return React.createElement(Component, { ...newProps, elementRef: ref }, _get(props, 'children')); }); return Object.assign({}, ForwardedComponent, config.attach); } |