I am creating a wrapper component for icons that I import using react-icons
. Here is an example of how it looks right now:
import { FaTwitter as Twitter} from 'react-icons/fa'
import { Icon } from './elements
<Icon>
<Twitter />
<Icon>
Now, this works just as I want it to -- but I would like to simplify the code. Ideally, I'd like it to look/work like this:
<Icon name='twitter' />
Any idea how to do this?
NOTE: In case it helps, here is current code for my Icon
component:
export const Icon = props => <IconBase {...props} />
The <IconBase>
component is just some styles from styled-components
.
UPDATE
I just want to note that the Twitter example is just that -- an example. I'm looking for a solution that will work no matter what name I pass to the <Icon>
component. So, in other words, all of the following (and more) will work:
<Icon name="Facebook" />
<Icon name="Search" />
<Icon name="Menu" />
Each of these would be equivalent to:
<Icon><Facebook /></Icon>
<Icon><Search /></Icon>
<Icon><Menu /></Icon>
In other words, no matter what icon I pull in from react-icons
, it will render properly vis-a-vis the name
prop.