反应本机向量不一致问题

时间:2020-06-15 20:39:14

标签: reactjs vector icons native

我花了很多时间来解决这个问题,但是找不到解决方案。豆豆 在如何从反应矢量图标获取图标方面需要您的帮助。在我的代码下面 package.json文件。我只想向导航栏添加菜单图标...感谢您的帮助

import React from 'react';
   import {View, Text, StyleSheet, Image, TouchableOpacity} from 'react-native';
   // import {FiMenu} from 'react-icons/fi';
   //import MenuIcon from '@material-ui/icons/Menu';
   import Icon from 'react-native-vector-icons/';
   const MenuNav = ({navigation}) => {
     const showDrawer = () => {
    navigation.openDrawer();
   };



 return (
    <View style={styles.menucontainer}>
      <TouchableOpacity style={styles.img} onPress={showDrawer}>
        <Image source={require('../imgs/menu.png')} />
        <Icon
          name="check"
          color="rgba(0, 0, 0, 0.38)"
          size={25}
          type="entypo"
        />
      </TouchableOpacity>
      <Text style={styles.text}>Menu</Text>
    </View>
    );
   };



 "dependencies": {
    "@material-ui/core": "^4.10.2",
    "@material-ui/icons": "^4.9.1",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/drawer": "^5.8.2",
    "@react-navigation/native": "^5.5.1",
    "@react-navigation/stack": "^5.5.1",
    "react": "16.11.0",
    "react-icons": "^3.10.0",
    "react-native": "0.62.2",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^3.0.5",
    "react-native-screens": "^2.8.0",
    "react-native-vector-icons": "^6.6.0"
   },

错误:元素类型无效:预期为字符串(对于内置组件)或 类/函数(用于复合组件),但得到:未定义。您可能忘记了 从定义的文件中导出您的组件,否则您可能混淆了 默认

和命名的导入。

1 个答案:

答案 0 :(得分:0)

您以错误的方式导入Icon

react-native-vector-icons中,您应该这样做:

import Icon from 'react-native-vector-icons/SimpleLineIcons'
// and replace SimpleLineIcons with the set of icons you want to use

这里有full list of the sets