美文网首页
react18 FC props没有children了

react18 FC props没有children了

作者: RickyWu585 | 来源:发表于2022-07-14 15:44 被阅读0次

    现在需要手动定义:因为有些情况下,children是没有意义的,所以最新的FC定义把children删掉了

    type Props = {
      children?: React.ReactNode
    };
    

    react<18FC定义:有PropsWithChildren

    type FC<P = {}> = FunctionComponent<P>;
    
        interface FunctionComponent<P = {}> {
            (props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
            propTypes?: WeakValidationMap<P> | undefined;
            contextTypes?: ValidationMap<any> | undefined;
            defaultProps?: Partial<P> | undefined;
            displayName?: string | undefined;
        }
    

    react18FC定义:无PropsWithChildren

    type FC<P = {}> = FunctionComponent<P>;
    
        interface FunctionComponent<P = {}> {
            (props: P, context?: any): ReactElement<any, any> | null;
            propTypes?: WeakValidationMap<P> | undefined;
            contextTypes?: ValidationMap<any> | undefined;
            defaultProps?: Partial<P> | undefined;
            displayName?: string | undefined;
        }
    

    相关文章

      网友评论

          本文标题:react18 FC props没有children了

          本文链接:https://www.haomeiwen.com/subject/nmffirtx.html