gpt4 book ai didi

javascript - "Type ' { child : Element[]; pictureUrl: string; } ' is not assignable to type ' IntrinsicAttributes & { children? : react 节点; }'

转载 作者:行者123 更新时间:2023-12-03 08:19:12 25 4
gpt4 key购买 nike

我遇到了 Typescript 和以下消息的问题:

{ child :元素[];图片网址:字符串; }' 不可分配给类型 'IntrinsicAttributes & { children?: ReactNode; }'

类型“IntrinsicAttributes & { children?: ReactNode;”上不存在属性“pictureUrl” }'

我真的不明白我做错了什么,有人看到问题了吗?

这是我的应用程序组件:

import React from 'react';
import { Root, Routes, addPrefetchExcludes } from 'react-static';
import { Link, Router } from '@reach/router';
import FancyDiv from 'components/FancyDiv';
import Dynamic from 'containers/Dynamic';
import './app.css';
import NavDomicile from './components/NavDomicile';

// Any routes that start with 'dynamic' will be treated as non-static routes
addPrefetchExcludes([ 'dynamic' ]);

function App() {
return (
<Root>
<NavDomicile pictureUrl="./assets/logo-lavigo-domicile.png">
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/blog">Blog</Link>
<Link to="/dynamic">Dynamic</Link>
</NavDomicile>
<div className="content">
<FancyDiv>
<React.Suspense fallback={<em>Loading...</em>}>
<Router>
<Dynamic path="dynamic" />
<Routes path="*" />
</Router>
</React.Suspense>
</FancyDiv>
</div>
</Root>
);
}

export default App;

And My Nav Component :

<!-- begin snippet: js hide: false console: true babel: false -->
import React, { ReactNode } from 'react';

interface INavProps {
pictureUrl?: string;
children?: ReactNode;
}

const NavDomicile: React.FC = ({ children, pictureUrl }: INavProps) => {
return (
<nav>
<div>
<img src={pictureUrl} />
</div>
<div>{children}</div>
</nav>
);
};
export default NavDomicile;

最佳答案

您应该为 React.FC 的泛型类型提供接口(interface)

const NavDomicile: React.FC<INavProps> = ({ children, pictureUrl }) => {


}

关于javascript - "Type ' { child : Element[]; pictureUrl: string; } ' is not assignable to type ' IntrinsicAttributes & { children? : react 节点; }',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61700558/

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