reactjs - React 和 typescript fortawesome 类型
问题描述
你好我有以下界面:
export interface IDropdownItems {
name: string;
link: string;
}
export interface ITag {
name: string;
link: string;
icon: any;
dropdownItems: IDropdownItems[] | null;
active: boolean;
}
export const SideBarTags: ITag[] = [
{
name: 'Tutoriais',
link: '../tutorials',
icon: faFileAlt,
dropdownItems: null,
active: false,
},
{
name: 'Avisos',
link: '../news',
icon: faNewspaper,
dropdownItems: null,
active: false,
},
{
name: 'Serviços',
link: '../services',
icon: faMeteor,
active: false,
dropdownItems: [
{ name: 'Elo Boost', link: '/eloBost' },
{ name: 'Duo Boost', link: '/duoBoost' },
{ name: 'MD10', link: '/eloBost' },
{ name: 'Coaching', link: '/duoBoost' },
{ name: 'Vitóriais', link: '/duoBoost' },
],
},
{
name: 'Carteira',
link: '../cartcredit',
icon: faWallet,
active: false,
dropdownItems: [
{ name: 'Histórico', link: '/history' },
{ name: 'Adicionar Crédito', link: '/add' },
],
},
];
但是这样我需要两次导入fortawesome 我想在我的图标上使用一个类型
我为打字稿找到了以下内容:
const coffeeLookup: IconLookup = { 前缀: 'fas', iconName: 'coffee' }
常量 coffeeIconDefinition: IconDefinition = findIconDefinition(coffeeLookup)
但我无法想象我将如何适应我的界面
解决方案
我不明白你为什么需要导入两次。你在谈论 fontawesome 吗?您是否尝试IconType
从 react-icon 模块输入您的图标?
推荐阅读
- javascript - Gulp:任务函数必须在 Gulp.set 中指定
- vue.js - 在Vue中删除当前选项时将选定值更改为null
- python - 为什么我使用 name.replace('N','n') 而不是 name.replace("N","n") 时收到错误
- python - 无法使用 Python beautifulsoup 从不需要的字符中清除字符串
- android - 在单元测试期间获取 NullPointerException 以订阅 ViewModel 中的 Observable
- sql - 使用 SQL 识别具有开始日期和结束日期的时间段
- r - 在嵌套列表中查找包含子元素的顶级元素
- javascript - 如何在 Cypress 中执行自定义命令?
- javascript - window.location.href 从 2019 年 3 月起在 chrome 中被屏蔽
- html - 使用链接媒体属性加载条件样式表失败