I am trying to optimize a component of mine with dynamic rendering, but I'm facing some issues, so this is my current situation:
I have an Alert
component that renders an alert message, along with an icon.
I have a Icons
module, which is a library of icons
I am currently rendering the icon as follows (this is not actual code, it's just to give the idea):
import * as icons from '../icons';
import DefaultIcon from '../icons';
function Alert(iconName='defaultIcon', message) {
function getIcon(iconName) {
if (iconName === 'defaultIcon') {
return DefaultIcon()
}
return icons[iconName]
}
return (
<div>
<span>{getIcon(iconName)}</span>
<span>{message}</span>
</div>
)
}
So, suppose Alert
gets called without iconName
most of the times, so the components doesn't need to import all of the icons at all.
I would like to avoid including all of the icons in the Alert
component by default, but only doing so if iconName
is specified
Is it even possible to do so?