Skip to content

Commit 95a44f2

Browse files
isArlekinAleksei
andauthored
fix: stop passing unnecessary props to DOM nodes (#52)
* Stop pass unnecessary props to dom node * Fix typings in DynamicIcon --------- Co-authored-by: Aleksei <[email protected]>
1 parent 516e735 commit 95a44f2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/react-web3-icons/src/components/DynamicIcon/LoadableIcon.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import React, { JSX } from "react";
33

44
import { Web3IconType } from "../../icons/full";
55
import { IconComponentBaseProps, symbolToComponentName } from "../../utils";
6+
import { omit } from "../../utils/omit";
67
import { IconPlaceholder } from "../Base/IconPlaceholder";
78

8-
export type LoadableIconProps = IconComponentBaseProps & {
9+
export type LoadableIconProps = Omit<IconComponentBaseProps, "loader"> & {
910
iconKey: Web3IconType | string;
1011
abbreviation: string;
12+
fallback?: Pick<IconComponentBaseProps, "loader">;
1113
fallbackComponent?: JSX.Element;
1214
};
1315

@@ -22,7 +24,12 @@ export const LoadableIcon = loadable(
2224
const mode = mono ? "mono" : "full";
2325
const componentName = symbolToComponentName(iconKey);
2426
try {
25-
return import(`../icons/${mode}/${componentName}`);
27+
const iconEsModule = await import(`../icons/${mode}/${componentName}`);
28+
const IconComponent = iconEsModule.default;
29+
const imageComponentProps = omit(props, ["fallback"]);
30+
return {
31+
default: () => <IconComponent {...imageComponentProps} />,
32+
};
2633
} catch (err) {
2734
if (fallbackComponent) {
2835
return {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const omit = <T extends Record<string, unknown>>(
2+
obj: T,
3+
keys: (keyof T)[],
4+
) => {
5+
const exclude = new Set(keys);
6+
return Object.fromEntries(
7+
(Object.entries(obj) as [keyof T, T[keyof T]][]).filter(([key]) => {
8+
return !exclude.has(key);
9+
}),
10+
);
11+
};

0 commit comments

Comments
 (0)