view config getter callback for component 'div' must be a function (received 'undefined'). Make sure to start component names with a capital letter
Asked Answered
V

11

43

Error is: Invariant Violation: view config getter callback for component 'div' must be a function (received 'undefined'). Make sure to start component names with a capital letter. I am getting this error while trying to retrieve data from firebase into table component of react native that is ReactTable and also giving an empty array in the console when viewing data in my console and hence nothing appears in the output.

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 }
});
Vampirism answered 30/4, 2020 at 12:14 Comment(0)
M
47

You cannot use div in react native change it with View

change

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

to

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

Hope this helps!

Manful answered 30/4, 2020 at 12:17 Comment(7)
Thanks for solving my doubt now error is not showing after changing code, but not able to show any data of database on my screen @user12129132Vampirism
Then there is a problem in retrieving data from firebase, check it onceManful
An empty array is printing in console @user12129132Vampirism
can you just go through my code to check whether it is correct or not ? @user12129132Vampirism
check what you are getting query.once("value").then((snapshot) => { after this by consoling snapshotManful
console.log(snapshot) is correctly printing database values @user12129132Vampirism
Have you checked whether you are getting correct data by consoling data after data.push(singleObj);Manful
I
74

Sometimes this error occurs when the import of your component is not correct. In my react-native project, FlatList got imported from react-native-web instead of react-native framework which resulted in above error. When I imported it from react-native framework it worked fine.

Illbehaved answered 7/5, 2021 at 5:15 Comment(2)
This was the solution for me too! The Visual Studio Code has imported incorrectly from 'react-native-web' a few times now!Parol
Yes. My 'SafeAreaView' was imported from react-native-web instead of react-native and that caused the problem. Thank you.Jovita
M
47

You cannot use div in react native change it with View

change

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

to

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

Hope this helps!

Manful answered 30/4, 2020 at 12:17 Comment(7)
Thanks for solving my doubt now error is not showing after changing code, but not able to show any data of database on my screen @user12129132Vampirism
Then there is a problem in retrieving data from firebase, check it onceManful
An empty array is printing in console @user12129132Vampirism
can you just go through my code to check whether it is correct or not ? @user12129132Vampirism
check what you are getting query.once("value").then((snapshot) => { after this by consoling snapshotManful
console.log(snapshot) is correctly printing database values @user12129132Vampirism
Have you checked whether you are getting correct data by consoling data after data.push(singleObj);Manful
M
6

I got a similar error which says

Error is: Invariant Violation: view config getter callback for component 'form' must be a function (received 'undefined').

my problem was that I was using a web version that uses from formik so I just needed to use react native one which is changing Form to View.

Hope it helps Others.

Mideast answered 27/9, 2021 at 15:39 Comment(1)
I got the same error because I imported View from react-native-web instead of react-native.Chicky
R
3

I was having the problem it got fixed by just changing destination from where I am importing

Eg. I had to import TouchableOpacity. Inside VSCode the code snippet chose wrong library and so it was inserted like this

import { TouchableOpacity } from "react-native-web";

instead of

import { TouchableOpacity } from "react-native";

Changing it inside correct import helped me fix the issue.

Just answered to let you know this is also a fixation.

Roanne answered 19/7, 2022 at 18:37 Comment(0)
P
2

The error occurs when you import the component from wrong component module for eq. if you import the "TouchableOpacity" from react-native-web instead of react-native

Perihelion answered 20/4, 2022 at 10:48 Comment(2)
This was super helpful... this is the cause of that errorAsare
Indeed it does for me, thanks !Handsomely
D
1

I just experienced this in another module: React-Insta-Stories. After spending about an hour troubleshooting, I now discovered that the module was never meant for React Native. So, if you have this type of error, check to confirm that the module is meant to work in React Native and not only for react.

Debbydebee answered 19/8, 2022 at 8:5 Comment(0)
B
1

Sometimes this error occurs when the import of your component is not correct. In my react-native project, Flat List got imported from react-native-web instead of react-native framework which resulted in above error. When I imported it from react-native framework it worked fine.

import { TouchableOpacity } from "react-native";
Bushcraft answered 4/9, 2023 at 9:5 Comment(0)
E
1

The reason for this error is because of the wrong imports. in react native there are imports for view in =>react-native-web =>react-native =>react-native-gesture-handler You will need to import the right one for your project. react-native-web wont work with react-native.

Erato answered 2/5 at 6:40 Comment(0)
R
0

A lot of times it happened to me. Whenever I Declare TouchableOpacity or other components, vscode automatically import the component from 'react-native-web'. But we should import it from 'react-native' So make sure that we import it from 'react-native'

Rhino answered 16/6, 2022 at 17:46 Comment(0)
C
0

The same problem may occur if you use the function as a component and write it in lower case. it should be MyStack in this example

  function myStack() {
        return (
            <Stack.Navigator>
               <Stack.Screen name="Drawer" component={MyDrawer} />
              <Stack.Screen name="Home" component={TabNavigator} />
            </Stack.Navigator>
          );
      }

export default function Router() {
  return (
    <NavigationContainer>
     <myStack/>
    </NavigationContainer>
  );
}
Carolanncarole answered 7/7, 2023 at 11:7 Comment(0)
B
-3

Sometime the View you defined must be in Capital letter.

const PresentationalComponent = (props) => {
   return (
    **<View>**
     <HeaderText></HeaderText>
    **</View>**
    
    
        
      
   )
}
export default PresentationalComponent
Biota answered 6/4, 2021 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.