Reputation: 163
I have a component that I want to reuse, and in different instances, I want different icons that come with different tags "Entypo" and "AntDesign". I would like to switch them on type property. Here is the idea:
const tag = type === 'home' ? 'Entypo' : 'AntDesign';
<{tag} name='someName' />
But it doesn't go through. Is there something I am missing? Or is there another way?
Upvotes: 2
Views: 192
Reputation: 2185
If Entypo
and AntDesign
are components (eg. imported from react-native-vector-icons
), then you should be able to do it like so:
const Tag = type === 'home' ? Entypo : AntDesign;
<Tag name='someName' />
Upvotes: 3