组件'div'的视图配置getter回调必须是一个函数(接收为'undefined')。确保组件名称以大写字母开头

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

[错误是:永久违反:组件'div'的view config getter回调必须是一个函数(接收为'undefined')。确保组件名称以大写字母开头。我在尝试从Firebase到React Native的表组件(ReactTable)中检索数据时遇到此错误,并且在控制台中查看数据时在控制台中提供了一个空数组,因此输出中没有任何内容。

import React, { Component } from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import ReactTable from 'react-table';
import firebase from 'firebase';


const firebaseConfig = {
...
};
firebase.initializeApp(firebaseConfig);


export default class Form1 extends Component {
constructor(props) {
    super(props);

    this.state = {
        data: [],
        columns: [
            {
                Header: "email",
                accessor: "email"
            },
            {
                Header: "password",
                accessor: "password"
            }
        ]
    }
}

componentDidMount() {
    const data = [];
    var query = firebase.database().ref("users");
    query.once("value").then((snapshot) => {
        snapshot.forEach((childSnapshot, index) => {
            let singleObj = {
                email: childSnapshot.val().email,
                password: childSnapshot.val().password,
            }
            data.push(singleObj);

            if (index === snapshot.length - 1) {
                this.setState({ data: data });
            }
        });
    });
}

render() {
    return (
        <div>
            {this.state.data.length > 0 && <ReactTable data={this.state.data} columns= 
{this.state.columns} />}
        </div>
    );
}
}

const styles = StyleSheet.create({
container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
head: { height: 40, backgroundColor: '#f1f8ff' },
text: { margin: 6 }
});
javascript react-native firebase-realtime-database data-retrieval
1个回答
1
投票

您不能使用div来对div进行本机更改更改

      <div>
            {this.state.data.length > 0 && <ReactTable data={this.state.data} columns= 
{this.state.columns} />}
        </div>

        <View>
            {this.state.data.length > 0 && <ReactTable data={this.state.data} columns= 
{this.state.columns} />}
        </View>

希望这会有所帮助!

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