我用来将一些内容呈现为列表,在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.
当我使用它时,它正在工作。但是当我使用的时候,我得到了那些错误。我怎样才能解决这个问题?
(我已经实现了从firebase获取数据的相关方法,并将这些数据分配给状态中的v_list。我这里没有包含这些方法。它们工作正常。)
检查您的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+
。