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