reactjs - React.js:如何将 Fontawsome 图标作为道具发送?
问题描述
我使用这个对象作为 React.js 组件道具。但发送后,FontAwsome 找不到通过的图标
{
key: 'editButton',
title: 'Edit',
icon: 'faEdit',
function: null,
type: 'default ',
},
{
key: 'deleteButton',
title: 'Delete',
icon: 'faTrash',
type: 'danger',
function: null,
},
我的组件:
<FontAwesomeIcon icon={item.icon} />
错误:
index.js:1 Could not find icon {prefix: "fas", iconName: "faEdit"}
解决方案
如果您需要将其作为字符串值传递,那么您需要先预先注册它们: https ://fontawesome.com/how-to-use/javascript-api/methods/library-add
另请参阅:从 Fontawesome 导入所有图标
否则,您可以显式传递它们:
import { faEdit } from '@fortawesome/free-solid-svg-icons';
...
{
key: 'editButton',
title: 'Edit',
icon: faEdit,
function: null,
type: 'default ',
},
推荐阅读
- reactjs - 两个下拉菜单,使用反应钩子根据第一个下拉选择显示第二个下拉列表
- laravel - 如何在 laravel 中获取值 json
- python - Python - 为什么我的所有对象都继承自其他对象
- python - 无法执行python单元测试用例
- java - 导出的可运行 jar 不起作用,因为 java.net.URL.toString() 为空?
- django - Django 模板标签
- postgresql - 当我减去两列时,“没有运算符与给定的名称和参数类型匹配”
- javascript - 每隔一个字符输入插入一个点
- c# - 是否可以使用 Microsoft Graph API 将视频流式传输到浏览器?
- java - 数独生成器创建一个无限循环