@ncds/ui-admin-icon 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/dist/cjs/index.js +22 -13
- package/dist/cjs/map.js +1549 -1549
- package/dist/esm/index.js +23 -14
- package/dist/esm/map.js +1549 -1549
- package/dist/types/map.d.ts +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import React, { useEffect,
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import { getIcon } from './map';
|
|
3
3
|
const Icon = ({ name, ...props }) => {
|
|
4
|
-
const
|
|
5
|
-
const [
|
|
4
|
+
const IconComponentRef = useRef(null);
|
|
5
|
+
const [, forceUpdate] = React.useState({});
|
|
6
6
|
useEffect(() => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
IconComponentRef.current = null;
|
|
8
|
+
let isMounted = true;
|
|
9
|
+
const iconImport = getIcon(name);
|
|
10
|
+
if (iconImport) {
|
|
11
|
+
iconImport()
|
|
12
|
+
.then((iconModule) => {
|
|
13
|
+
if (isMounted && iconModule?.default) {
|
|
14
|
+
IconComponentRef.current = iconModule.default;
|
|
15
|
+
forceUpdate({});
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
console.error(`Error loading icon: ${name}`, error);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
isMounted = false;
|
|
24
|
+
};
|
|
16
25
|
}, [name]);
|
|
17
|
-
const IconComponent =
|
|
18
|
-
if (
|
|
26
|
+
const IconComponent = IconComponentRef.current;
|
|
27
|
+
if (!IconComponent)
|
|
19
28
|
return null;
|
|
20
29
|
return React.createElement(IconComponent, { ...props });
|
|
21
30
|
};
|