reactjs - 如何处理错误“找不到图标”
问题描述
我动态创建图标名称,有时会发生库中没有对应的图标。有什么方法可以捕获错误并使用默认图标名称?
解决方案
您可以使用findIconDefinition
以下方式查找图标名称:
// Set params with details of the icon you're looking up depending
// on what variant you're using.
let params = {
iconName: iconName,
prefix: prefix
// other entries as needed
};
if (!findIconDefinition(params)) {
// Use default icon here.
}
详细信息findIconDefinition
在https://fontawesome.com/how-to-use/javascript-api/methods/findicondefinition
推荐阅读
- python - 如何优化python中的嵌套循环?
- youtube-api - 合法的 YouTube API 合规审核?
- excel - If(And( arguments + Vlookup 没有返回预期值
- c# - 尽管添加了 application/json 标头,但请求仍为“text/plain”
- kubernetes - Kubernetes 会在重启 Pod 之前发送信号吗?
- c# - C# 中的 AWS DynamoDb 事务
- sql - 日期时间倒退
- javascript - 拦截 react native webview 的每一个请求
- php - 超越多对多。如何获取与数据透视表不直接相关的数据?
- python - 考虑前行的值,将函数应用于 pandas 数据框列