36

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 }
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
developer_user
  • 463
  • 2
  • 5
  • 13

9 Answers9

70

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.

Shweta
  • 1,099
  • 1
  • 9
  • 9
  • 6
    This was the solution for me too! The Visual Studio Code has imported incorrectly from 'react-native-web' a few times now! – Jules May 10 '21 at 15:50
  • Yes. My 'SafeAreaView' was imported from react-native-web instead of react-native and that caused the problem. Thank you. – Raja C May 29 '22 at 08:14
41

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!

Goskula Jayachandra
  • 3,931
  • 2
  • 12
  • 22
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.

navidabasi
  • 161
  • 1
  • 10
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

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31580008) – Stanley Apr 23 '22 at 04:19
  • 1
    This was super helpful... this is the cause of that error – David Attah May 24 '22 at 15:06
  • Indeed it does for me, thanks ! – Biologeek Jul 03 '22 at 07:59
2

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.

Adnan Siddique
  • 324
  • 3
  • 9
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.

AnatuGreen
  • 579
  • 7
  • 14
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'

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>
  );
}
-2

Sometime the View you defined must be in Capital letter.

const PresentationalComponent = (props) => {
   return (
    **<View>**
     <HeaderText></HeaderText>
    **</View>**
    
    
        
      
   )
}
export default PresentationalComponent
Debendra Dash
  • 5,334
  • 46
  • 38