Skip to content

Commit

Permalink
feat(Icon): wrap async IIFE with useEffect hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aneurysmjs committed Jul 7, 2019
1 parent 4b024c0 commit 0d8a2d7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/app/components/base/Icon/Icon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow strict
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';

import './Icon.scss';

Expand All @@ -11,16 +11,18 @@ type PropsType = {

const Icon = ({ path, size }: PropsType) => {
const [iconPath, setIconPath] = useState('');

(async () => {
try {
// $FlowIgnore
const icon = await import('@/assets/svg/' + path + '.svg');
setIconPath(icon.default);
// eslint-disable-next-line no-empty
} catch (err) {
}
})();

useEffect(() => {
(async () => {
try {
// $FlowIgnore
const icon = await import('@/assets/svg/' + path + '.svg');
setIconPath(icon.default);
// eslint-disable-next-line no-empty
} catch (err) {
}
})();
}, [path]);

return (
<img
Expand Down

0 comments on commit 0d8a2d7

Please sign in to comment.