Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static load(allIcons) {
// 注册所有图标
ReactIcon.add(...Object.keys(allIcons).map((key) => allIcons[key]));
// 还原get函数
ReactIcon.get = originalGetIcon;
// 通过强制刷新来,显示异步加载的图标
this.instances.forEach((instance) => instance.forceUpdate());
// 移除所有队列
this.instances.length = 0;
}
constructor(props) {
import React from 'react'; import PropTypes from 'prop-types';
import ReactIcon from '@ant-design/icons-react';
import { generate } from '@ant-design/icons-react/es/utils';
// 原始获取图标函数
const originalGetIcon = ReactIcon.get.bind(ReactIcon);
// 覆盖get函数,在图标未加载前,返回一个渲染AutoReloadIcon来控制自动刷新
ReactIcon.get = function (key) {
const target = originalGetIcon(key);
if (target) {
return target;
}
return {
icon: (primaryColor, secondaryColor) => {
return {
tag: function AutoReloadIconWrapper(props) {
return (