Home > Mobile >  Getting Error with react native Vector icons, using it in Project
Getting Error with react native Vector icons, using it in Project

Time:11-05

I am trying to use React native vector icons,somehow i am getting this as an error

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

When i used npm to install react native vector icons, i went like this :

npm install --save react-native-vector-icons

Now why am i getting this as an Error? react-native-vector-icons also shows in my package.json file, however i noticed I could not link it as i get error: unknown command 'link'

How do i resolve this?

CodePudding user response:

Usually, this error is about the wrong type of the component (you expect you pass a component or string but you pass something else). In your case, I think the problem is how you import components. Try to change

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

to

import { Icon } from "react-native-vector-icons/MaterialIcons";

Another possible problem is the way you install icons. It needs additional platform-specific settings which you can find here: https://github.com/oblador/react-native-vector-icons#installation

  • Related