使用时出现Invariant Violation错误 和 在反应原生的android上

问题描述 投票:1回答:1

我用来将一些内容呈现为列表,在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 react-native-elements
1个回答
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

您使用ListroundAvatar这一事实表明您可能正在尝试使用版本0.19.1中的组件,但安装了版本1+

© www.soinside.com 2019 - 2024. All rights reserved.