1

我用来将一些内容呈现为列表,在 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。我没有在这里包含这些方法。它们工作正常。)

4

1 回答 1

3

检查您的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已被弃用。您可以通过查看依赖项的博客了解更多关于已弃用和未弃用的内容。还有几个 props也被弃用了,你可以在这里ListItem查看哪些。

List您正在使用的事实roundAvatar表明您可能正在尝试使用版本中的组件0.19.11+已安装版本。

于 2019-03-11T14:54:31.787 回答