Dex
Dex

Reputation: 163

Is it possible to wrap the tag into a variable?

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

Answers (1)

Marek Lisik
Marek Lisik

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

Related Questions