我正在使用和将本机内容呈现为列表,以react-native的形式出现。这是我的代码。
import React, { Component } from 'react';
import { Text, View, FlatList, StyleSheet, TextInput } from 'react-native';
import { Card, List, ListItem, Button, Icon, Image } from 'react-native-elements';
import { fb, database } from '../../../config/config';
export default class Vehicles extends Component {
constructor (props) {
super(props);
this.state = {
v_number: '',
v_brand: '',
v_type: '',
user: null,
v_list: []
};
}
render () {
return (
<View style={styles.vehicleContainer}>
<Button
title=" Logout"
/>
{
this.state.v_list != null ? (
<List>
<FlatList
data={this.state.v_list}
renderItem={({ item }) => (
<ListItem
roundAvatar
title={item.details.vehicle_number}
subtitle={item.details.vehicle_type}
leftAvatar={{ source: { uri: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg' } }}
/>
)}
/>
</List>
) : (
<Text>Empty</Text>
)
}
</View>
);
}
}
const styles = StyleSheet.create({
vehicleContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#ffffff'
},
ti1: {
borderColor: 'gray',
borderWidth: 1,
width: 300,
height: 40
}
});
执行此代码后出现两个错误。第一个是
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.
第二个错误是
Invariant Violation: Invariant Violation: 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.
当我使用和时,它正在工作。但是当我使用和时,出现了这些错误。 我该如何解决?
(我已经实现了relevent方法,以从firebase中获取数据并将这些数据分配给状态中的v_list。我这里没有包括这些方法。它们工作正常。)
答案 0 :(得分:1)
检查您的react-native-elements
版本。
此错误通常是由于导入不存在的内容引起的。
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.
在版本1+
中,组件List
已弃用。通过检查依赖项的blog,可以了解有关不赞成使用的内容和不赞成使用的内容的更多信息。此外,ListItem
的几个道具也已被弃用,您可以看到here的道具。
您正在使用List
和roundAvatar
的事实表明您可能正在尝试使用版本0.19.1
但安装了版本1+
的组件。