【发布时间】:2021-08-13 05:28:50
【问题描述】:
我正在尝试使用 reactjs 和 typescript 构建一个动态菜单系统。
我的配置如下所示:
import {TableIcon} from "@heroicons/react/solid";
type route = {
icon: React.ReactNode,
path: string,
title: string,
}
export const navRoutes = () : route[] => {
return [
{
icon: TableIcon,
path: '/',
title: 'Home'
},
]
}
在我的导航组件中,我正在做
{navRoutes().map((item) => (
<a key={item.title} href={item.path}>
<item.icon /> // also tried {item.icon}
{item.title}
</a>
))}
我收到一个错误,TS2604: JSX element type 'item.icon' does not have any construct or call signatures.
我在没有按预期工作的打字稿的情况下做了类似的事情——谁能告诉我我做错了什么?
【问题讨论】:
标签: javascript reactjs typescript tailwind-css