首页 > 解决方案 > 如何从 TypeScript 中的字符串名称动态构建元素?

问题描述

我有以下代码:

interface StyledTypographyProps extends TypographyProps {
    overrides?: { Typography: React.ComponentType };
}

export const StyledTypography: React.FunctionComponent<StyledTypographyProps> = (props) => {
    const { children, overrides, ...typographyProps } = props;

    const CustomTypography = overrides ?? MainTypography;

    return (
        <CustomTypography ref={ref} {...typographyProps}>
            {children}
        </CustomTypography>
    )
}

我收到以下错误:JSX element type 'CustomTypography' does not have any construct or call signatures.

任何想法我在这里缺少什么?

标签: reactjstypescript

解决方案


推荐阅读