Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import icons from multiple files in react native vector icons?

If I wanted to use Ionicons and MaterialDesign Icons from react native vector icons in the same file, how should I import it?

import Icon from 'react-native-vector-icons/MaterialIcons';

(and)

import Icon from 'react-native-vector-icons/Ionicons';

in the same file

like image 845
Roman Akash Avatar asked Apr 19 '17 12:04

Roman Akash


People also ask

How do I import multiple icons into react?

Since you already imported the icon library you want, you will not need to import it a second time. All you have to do is go back to the React icons page. Copy another icon that you want and paste it in the curly braces. This is how you can use as many icons as you need from the Font Awesome library.

Can I use Expo vector icons in react-native?

@expo/vector-icons This library is installed by default on the template project using npx create-expo-app and is part of the expo package. It is built on top of react-native-vector-icons and uses a similar API. It includes popular icon sets that you can browse at icons.


2 Answers

After going through the original source files I found out that the icons was exported like

export default iconSet

So you could just use any arbitrary name to import.

In that case, the final code will look like this:

import MaterialIcon from 'react-native-vector-icons/MaterialIcons;
import Ionicon from 'react-native-vector-icons/Ionicons';

Thank You Fran Rios

like image 115
Roman Akash Avatar answered Sep 17 '22 19:09

Roman Akash


You can take advantage of using the name you want on each import due type of exporting on react-native-vector-icons:

import IonIcon from 'react-native-vector-icons/Ionicons'
import MaterialIcon from 'react-native-vector-icons/MaterialIcons'

Then you can user IonIcon and MaterialIcon respectively in your code.

like image 33
Fran Rios Avatar answered Sep 17 '22 19:09

Fran Rios