File tree 1 file changed +13
-3
lines changed
packages/core/client/components/DynamicIcon
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
import SVG , { Props as SVGProps } from "react-inlinesvg" ;
2
2
3
- import React from "react" ;
3
+ import React , { useEffect , useState } from "react" ;
4
4
5
5
export interface DynamicIconProps extends Omit < SVGProps , "src" > {
6
6
icon : string ;
@@ -12,13 +12,23 @@ export const DynamicIcon: React.FC<DynamicIconProps> = ({
12
12
height,
13
13
...props
14
14
} ) => {
15
- return (
15
+ const [ error , setError ] = useState ( false ) ;
16
+ useEffect ( ( ) => setError ( false ) , [ icon ] ) ;
17
+ return ! error ? (
16
18
< SVG
17
19
width = { width }
18
20
height = { height }
19
21
src = { `/icons/${ icon } ` }
20
22
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 } } /> }
22
32
{ ...props }
23
33
/>
24
34
) ;
You can’t perform that action at this time.
0 commit comments