Closed
Description
I typically use namespacing in my react components to group similar components. I was wondering what the best approach to defining a type here would be. I generally do something like the example below, however using as ...
isn't ideal for me. Any other ideas how to properly type a react component that also has namespaced components?
interface IProps extends React.HTMLAttributes<HTMLDivElement> {
someProp?: any;
}
type TMyComponent = React.ForwardRefExoticComponent<IProps> & {
ChildComponent: typeof ChildComponent;
};
import ChildComponent from './ChildComponent';
const MyComponent = React.forwardRef(
({someProp, ...otherProps}: IProps, ref) => {
return <div {...otherProps} />;
}
) as TMyComponent;
MyComponent.ChildComponent = ChildComponent;
export default MyComponent;