@gapo_aria/icon
Advanced tools
Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1
@@ -35,4 +35,3 @@ var $azlKc$react = require("react"); | ||
try { | ||
ImportedIconRef.current = // @ts-ignore | ||
(await import(`@gapo_ui/icon/assets/${name}.svg`)).ReactComponent; | ||
ImportedIconRef.current = (await import(`@gapo_ui/icon/assets/${name}.svg`)).ReactComponent; | ||
if (onCompleted) onCompleted(name, ImportedIconRef.current); | ||
@@ -39,0 +38,0 @@ } catch (err) { |
@@ -19,4 +19,3 @@ import {useRef as $bQ1LR$useRef, useState as $bQ1LR$useState, useEffect as $bQ1LR$useEffect} from "react"; | ||
try { | ||
ImportedIconRef.current = // @ts-ignore | ||
(await import(`@gapo_ui/icon/assets/${name}.svg`)).ReactComponent; | ||
ImportedIconRef.current = (await import(`@gapo_ui/icon/assets/${name}.svg`)).ReactComponent; | ||
if (onCompleted) onCompleted(name, ImportedIconRef.current); | ||
@@ -23,0 +22,0 @@ } catch (err) { |
{ | ||
"name": "@gapo_aria/icon", | ||
"version": "0.0.1-alpha.0", | ||
"version": "0.0.1-alpha.1", | ||
"description": "Gapo UI components in React", | ||
@@ -20,3 +20,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "bf3c659dd0f3001e24f67f2a2dceed809a5a01d2" | ||
"gitHead": "48d5fd201c78288a862186f05aca04dfa80a8b9f" | ||
} |
@@ -1,5 +0,5 @@ | ||
import {useState, useRef, useEffect} from 'react'; | ||
import { useState, useRef, useEffect } from 'react' | ||
interface DynamicSVGImportOptions { | ||
onCompleted?: (name, ref)=> void, | ||
onCompleted?: (name, ref) => void | ||
onError?: (err) => void | ||
@@ -9,37 +9,38 @@ } | ||
interface DynamicSVGImportAria { | ||
error: any, | ||
loading: any, | ||
error: any | ||
loading: any | ||
SvgIcon: any | ||
} | ||
export function useDynamicSVGImport(name: string, options:DynamicSVGImportOptions = {}):DynamicSVGImportAria { | ||
const ImportedIconRef = useRef(); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(); | ||
export function useDynamicSVGImport( | ||
name: string, | ||
options: DynamicSVGImportOptions = {} | ||
): DynamicSVGImportAria { | ||
const ImportedIconRef = useRef() | ||
const [loading, setLoading] = useState(false) | ||
const [error, setError] = useState() | ||
const {onCompleted, onError} = options; | ||
const { onCompleted, onError } = options | ||
useEffect(() => { | ||
setLoading(true); | ||
setLoading(true) | ||
const importIcon = async () => { | ||
try { | ||
ImportedIconRef.current = ( | ||
// @ts-ignore | ||
await import(`@gapo_ui/icon/assets/${name}.svg`) | ||
).ReactComponent; | ||
ImportedIconRef.current = // @ts-ignore | ||
(await import(`@gapo_ui/icon/assets/${name}.svg`)).ReactComponent | ||
if (onCompleted) { | ||
onCompleted(name, ImportedIconRef.current); | ||
onCompleted(name, ImportedIconRef.current) | ||
} | ||
} catch (err) { | ||
if (onError) { | ||
onError(err); | ||
onError(err) | ||
} | ||
setError(err); | ||
setError(err) | ||
} finally { | ||
setLoading(false); | ||
setLoading(false) | ||
} | ||
}; | ||
importIcon(); | ||
}, [name, onCompleted, onError]); | ||
} | ||
importIcon() | ||
}, [name, onCompleted, onError]) | ||
return {error, loading, SvgIcon: ImportedIconRef.current}; | ||
return { error, loading, SvgIcon: ImportedIconRef.current } | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10423
143