【问题标题】:Why is the IonIcon component throwing an error but no the Text component?为什么 IonIcon 组件会抛出错误,而 Text 组件却没有?
【发布时间】:2020-07-14 16:51:37
【问题描述】:

我是 React Native 的新手,这是我的主要 App.js 组件:

import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { Ionincons} from '@expo/vector-icons'

export class App extends React.Component {
  render (){
    return (
      <View style={styles.container}>
       <Ionincons name='ios-pizza'/>
  </View>
  )
}
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  }
})

当我尝试运行这个简单的代码时,我收到以下消息:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, 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.

但是当我将 IonIcons 组件换成一个简单的 &lt;Text&gt;Hello&lt;/Text/&gt; 一切正常。 我在这里错过了什么?

【问题讨论】:

    标签: reactjs react-native react-native-android


    【解决方案1】:

    你有一个拼写错误,Ionincons 应该是Ionicons

    import { Ionicons } from '@expo/vector-icons';
    

    <Ionicons name='ios-pizza'/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-03
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 2023-02-04
      • 2021-06-12
      • 2017-08-02
      • 2018-02-25
      相关资源
      最近更新 更多