gpt4 book ai didi

javascript - “组件”不能用作 JSX 组件。下一页

转载 作者:行者123 更新时间:2023-12-05 00:36:57 26 4
gpt4 key购买 nike

这是 _app.tsx 的外观:

function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
我在构建项目时遇到了这个错误:
Type error: 'Component' cannot be used as a JSX component.
Its element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element.
Type 'Component<{}, any, any>' is not assignable to type 'Element | ElementClass | null'.
Type 'Component<{}, any, any>' is not assignable to type 'ElementClass'.
The types returned by 'render()' are incompatible between these types.
Type 'React.ReactNode' is not assignable to type 'import("/Users/user/node_modules/@types/react/index").ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
这些是 react 版本:
"react": "17.0.2",
"react-dom": "17.0.2",
"@types/react": "17.0.26",
我尝试切换到 18 版本,它工作,但我收到此错误: Hydration failed because the initial UI does not match what was rendered on the server

最佳答案

将以下代码添加到 package.json文件

"resolutions": {
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2"
}
然后重新安装软件包
yarn
  • 如果使用 npm

  • npm i

    关于javascript - “组件”不能用作 JSX 组件。下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71974065/

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