Skip to content

Commit 29099d2

Browse files
Thomas NairnThomas Nairn
Thomas Nairn
authored and
Thomas Nairn
committed
fix: Display error svg if invalid icon supplied
1 parent a6a4c0f commit 29099d2

File tree

1 file changed

+13
-3
lines changed
  • packages/core/client/components/DynamicIcon

1 file changed

+13
-3
lines changed

packages/core/client/components/DynamicIcon/index.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SVG, { Props as SVGProps } from "react-inlinesvg";
22

3-
import React from "react";
3+
import React, { useEffect, useState } from "react";
44

55
export interface DynamicIconProps extends Omit<SVGProps, "src"> {
66
icon: string;
@@ -12,13 +12,23 @@ export const DynamicIcon: React.FC<DynamicIconProps> = ({
1212
height,
1313
...props
1414
}) => {
15-
return (
15+
const [error, setError] = useState(false);
16+
useEffect(() => setError(false), [icon]);
17+
return !error ? (
1618
<SVG
1719
width={width}
1820
height={height}
1921
src={`/icons/${icon}`}
2022
loader={<div style={{ width, height }} />}
21-
onError={console.log}
23+
onError={() => setError(true)}
24+
{...props}
25+
/>
26+
) : (
27+
<SVG
28+
width={width}
29+
height={height}
30+
src={`/icons/@styled-icons/fluentui-system-regular/DocumentError`}
31+
loader={<div style={{ width, height }} />}
2232
{...props}
2333
/>
2434
);

0 commit comments

Comments
 (0)