reactjs - 为什么 IonIcon 组件会抛出错误,而 Text 组件却没有?
问题描述
我是 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组件时,
<Text>Hello</Text/>
一切正常。我在这里想念什么?
解决方案
你有一个拼写错误,Ionincons
应该是Ionicons
:
import { Ionicons } from '@expo/vector-icons';
和
<Ionicons name='ios-pizza'/>
推荐阅读
- excel - 我可以使用 VBA 一次更改所有图形的颜色吗?
- jestjs - JEST react-testing-library 无法读取未定义的属性“推送”
- highcharts - 折叠/展开子节点
- csv - 如何将 CSV 文件自动导入实体?
- python - Python“int64”无法转换为 MySQL 类型
- android - 为什么我的 RecyclerView 在放置在 AppBarLayout 中时不滚动?
- laravel - 什么是 Laravel Forge > 站点详细信息 > 元 > 标签?
- python - 如何提高 python opencv 的性能?
- asp.net-core - 为什么我的单选列表在模型绑定上转换为多选列表?
- javascript - JavaScript,遍历数组对象