gpt4 book ai didi

reactjs - 使用 Route render 时,ReactComponent 没有与类型 'IntrinsicAttributes & { children?: ReactNode; }' 相同的属性

转载 作者:行者123 更新时间:2023-12-02 02:58:06 29 4
gpt4 key购买 nike

使用时:

<Route path={rootPath} exact render={props => <LoginLayout {...props} />} />

在typescript LoginLayout中提示错误时:

Type '{ history: History<PoorMansUnknown>; location: Location<PoorMansUnknown>; match: match<any>; staticContext?: StaticContext | undefined; }' has no properties in common with type 'IntrinsicAttributes & { children?: ReactNode; }'.ts(2559)

我尝试添加:

const LoginLayout:FunctionComponent = (props: any) => { ... };

<Route path={rootPath} exact render={(props: any) => <LoginLayout {...props} />} />

但是这不起作用。我也尝试过:

const LoginLayout:FunctionComponent = (props: RouteComponentProps) => { ... };

<Route path={rootPath} exact render={(props: RouteComponentProps) => <LoginLayout {...props} />} />

这不起作用...

最佳答案

它会提示,因为您将 Prop (RouteComponentProps)传递给了不希望获得它们的组件。修复:

const LoginLayout: FunctionComponent<RouteComponentProps> = () => {...};

或者更短:

const LoginLayout: FC<RouteComponentProps> = () => {...};

Playground

关于reactjs - 使用 Route render 时,ReactComponent 没有与类型 'IntrinsicAttributes & { children?: ReactNode; }' 相同的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60631323/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com