FortAwesome / react-fontawesome

Font Awesome React component
https://fontawesome.com
MIT License
3.67k stars 264 forks source link

macros not accepting iconName as variable #504

Closed nassif7 closed 2 years ago

nassif7 commented 2 years ago

Describe the bug I am Trying to make an Icon component that takes IconeName as a prop and pass this to a <FontAwesomeIcon icon={regular(iconeName)}/>

but i am getting compile error Only string literals are supported when referencing icons (use a string here instead)

in case i do this <FontAwesomeIcon icon={solid('phone')} /> it works but this

const icon:IconName = 'phone'
<FontAwesomeIcon icon={solid(icon)} />

doesn't work

I am using macros and fontawesome 6

robmadole commented 2 years ago

Hi @nassif7 that's not supported with the macro. Please take a look at the docs and see if there is an alternative way that will work for you. If you are still having troubles let us know.

nassif7 commented 2 years ago

Hello @robmadole, thank you for the reply. do you think will be supported any soon ?

robmadole commented 2 years ago

Sorry, no @nassif7. This is a restriction of how Babel works that we don't have a solution for. You can think of this more akin to strict typing. Babel has to know what the icon is before it outputs the final JS. So using dynamic icon names is not possible with this current method.