Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:元素类型无效,需要字符串(对于内置组件)或类/函数(对于复合元素)_Javascript_React Native_Firebase Realtime Database_React Data Table Component - Fatal编程技术网

Javascript 错误:元素类型无效,需要字符串(对于内置组件)或类/函数(对于复合元素)

Javascript 错误:元素类型无效,需要字符串(对于内置组件)或类/函数(对于复合元素),javascript,react-native,firebase-realtime-database,react-data-table-component,Javascript,React Native,Firebase Realtime Database,React Data Table Component,我正在从firebase获取数据,并尝试以表格格式显示所有数据 我发现ReactTable是以列和行的形式打印所有检索到的数据的好方法,因此我选择此方法以表的形式打印数据。 但它无法打印列和行中的数据,而是显示以下错误: 错误:元素类型无效。内置组件需要字符串,复合元素需要类/函数 请纠正错误的代码,并尝试解决我的问题,因为我尝试了这么长时间的代码,仍然无法解决错误 import React, { Component } from 'react'; import { StyleSheet, Vi

我正在从firebase获取数据,并尝试以表格格式显示所有数据

我发现ReactTable是以列和行的形式打印所有检索到的数据的好方法,因此我选择此方法以表的形式打印数据。 但它无法打印列和行中的数据,而是显示以下错误:

错误:元素类型无效。内置组件需要字符串,复合元素需要类/函数

请纠正错误的代码,并尝试解决我的问题,因为我尝试了这么长时间的代码,仍然无法解决错误

import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';

import ReactTable from 'react-table';


import firebase from 'firebase';


const firebaseConfig = {
apiKey: "XXXXX",
authDomain: "XXXXX",
databaseURL: "XXXXX",
projectId: "XXXXX",
storageBucket: "XXXXX",
messagingSenderId: "XXXXX",
appId: "XXXX",
measurementId: "XXXX"
};
firebase.initializeApp(firebaseConfig);
export default class Form1 extends Component {
constructor(props) {
super(props);

this.state = {
   data: []
}


}
componentDidMount() {
firebase.database().ref('users').on('value',snapshot => {
   const data = [];
   snapshot.forEach((childSnapShot) => {
    const locker = {
        email: child.val().email,
        password: child.val().password,
       // price: child.val().price,
     };
     data.push(locker);
    });
   this.setState(prevState => {
    return { data: [...prevState.data, ...data] };
  });
  console.log(this.state.data)
});
}

render() {
const columns = [
  {
    Header: "email",
    accessor: "email"
  },
  {
    Header: "password",
    accessor: "password"
  }
  ];
return (
   <div>
    <ReactTable data={this.state.data} columns={columns} />
  </div>
);
}
}

const styles = StyleSheet.create({
container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
head: { height: 40, backgroundColor: '#f1f8ff' },
text: { margin: 6 }
});

我在你的代码中发现了一些小错误并改正了它。我认为您应该首先遵循Firebase和React文档,因为错误是非常基本的。如果这个答案对你有帮助,请告诉我

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

const firebaseConfig = {
    apiKey: "XXXXX",
    authDomain: "XXXXX",
    databaseURL: "XXXXX",
    projectId: "XXXXX",
    storageBucket: "XXXXX",
    messagingSenderId: "XXXXX",
    appId: "XXXX",
    measurementId: "XXXX"
};
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 (
            <View>
                {this.state.data.length > 0 && <ReactTable data={this.state.data} columns={this.state.columns} />}
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
    head: { height: 40, backgroundColor: '#f1f8ff' },
    text: { margin: 6 }
});

这回答了你的问题吗?您尚未声明任何React类组件。所有这些都需要在React类组件中完成。最后一条评论听起来像是一个伟大答案@NeetinSolanki的开始你@Neetin Solanki提供的链接没有用。如果您在我的代码中发现错误,这将对我很有帮助。在更改我的代码后,您更正了它,它将显示此错误。组件“div”的不变冲突视图配置getter回调必须是接收到“undefined”的函数。确保组件名称以大写字母开头@Neetin Solankia您在React或React Native中进行开发吗?React Native@Neetin Solankii如果您在React Native中工作,那么它将不支持html标记,并且它也不支持ReactTable。好的,我将浏览链接。谢谢:@Neetin Solanki