reactjs - 没有重载匹配此调用。反应
问题描述
我正在使用侧边栏菜单代码并使用 const 值在网站中显示和隐藏侧边栏菜单。但是我在打字时遇到错误。这是我的代码:
let Navigation = () => {
const [sidebar, setSidebar] = React.useState(false);
const showSidebar = () => setSidebar(!sidebar);
}
return(
<nav className="navbar-default navbar-static-side main-navigation" role="navigation">
<div className="sidebar-collapse">
<IconContext.Provider value={{ color: '#fff' }}>
<Nav>
<NavIcon to='#'>
<FaIcons.FaBars onClick={showSidebar} />
</NavIcon>
</Nav>
<SidebarNav sidebar= {sidebar}>
<SidebarWrap>
<NavIcon to='#'>
<AiIcons.AiOutlineClose onClick={showSidebar} />
</NavIcon>
<NavIcon to='#'>
<img src={logo} width="70%" />
</NavIcon>
</SidebarWrap>
</SidebarNav>
</IconContext.Provider>
</div>
</nav>
)
export default Navigation
但我得到了错误,
No overload matches this call.
Overload 1 of 2, '(props: Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>, "slot" | "style" | "title" | "children" | ... 250 more ... | "onTransitionEndCapture"> & { ...; }, "ref" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "ref" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }): ReactElement<...>', gave the following error.
Type '{ children: Element; sidebar: boolean; }' is not assignable to type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>, "slot" | ... 253 more ... | "onTransitionEndCapture"> & { ...; }, "ref" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "ref" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }'.
Property 'sidebar' does not exist on type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>, "slot" | ... 253 more ... | "onTransitionEndCapture"> & { ...; }, "ref" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "ref" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }'.
Overload 2 of 2, '(props: StyledComponentPropsWithAs<"nav", any, {}, never, "nav">): ReactElement<StyledComponentPropsWithAs<"nav", any, {}, never, "nav">, string | ... 1 more ... | (new (props: any) => Component<...>)>', gave the following error.
Type '{ children: Element; sidebar: boolean; }' is not assignable to type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>, "slot" | ... 253 more ... | "onTransitionEndCapture"> & { ...; }, "ref" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "ref" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }'.
Property 'sidebar' does not exist on type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>, "slot" | ... 253 more ... | "onTransitionEndCapture"> & { ...; }, "ref" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "ref" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }'. TS2769
排队 ,
<SidebarNav sidebar= {sidebar}>
它不允许我在标签中使用侧边栏。
解决方案
此错误来自您提供给侧边栏的内容与 Sibar 所期望的内容之间的类型差异。
你的 Sibar 组件是这样输入的吗
interface Props {
sidebar: boolean;
}
const Sidebar:FC<Props> = ({sidebar}: Props) => {
...yourCode
}
推荐阅读
- python - 如何在同一屏幕中创建独特的下拉菜单?
- python - Keras 结合了两个损失函数的值
- django - 姜戈 1.11。如何获取日期以每天更新自己
- angular - 升级到 ng7 后,E2e 测试无所作为
- .net - 强制 MVC JSON 解析器使用 RoundtripKind 解析 DateTime
- r - 加速 R 中的稀疏矩阵乘法
- python - TensorFlow Custom Estimator 预测抛出值错误
- javascript - 尝试自动扫描其他域上的闪存嵌入链接
- firebase - Firebase Pub/sub 触发器:偶尔执行多次
- vue.js - 嵌套的 vue 可拖动元素