React-native: 'FlatList' - React.createElement: type is invalid -- expected a string (for built-in components) or a class/function

Created on 14 Sep 2017  Â·  14Comments  Â·  Source: facebook/react-native

Warning: React.createElement: 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

While I'm using FlatList in my code, I'm getting this error. If I remove the FlatList code, the app is working fine. I imported FlastList in my code too and I'm export the container.

import { ListView, Text, FlatList } from 'react-native';

render() {
return (

  <FlatList
    data={[{ key: 'a' }, { key: 'b' }]}
    renderItem={({ item }) => <Text>{item.key}</Text>}
  />

);

}

export default connect(mapStateToProps, mapDispatchToProps)(HistoryViewport);

Please give some solution, where I'm doing mistake! What I forgot to export the component from the file?

2017-09-14_17-31-12

Ran Commands For Stack Overflow Locked

Most helpful comment

or if u are using 0.42 of react-native use ListView . ListView of 0.42 is changed to FlatList of 0.48

All 14 comments

@facebook-github-bot stack-overflow

Hey @anvesh523, thanks for posting this! @radko93 tells me this issue looks like a question that would be best asked on Stack Overflow. Stack Overflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only. See "What to Expect from Maintainers".

@anvesh523 Hai dude facing the issue, have you found any work around

@anvesh523 @NawazKhanMd What is your RN version?

I had that error when trying to use the FlatList with RN 0.42

@anvesh523
Was this settled?
I suffer from the same problem, too.

@marcodefreitas I'm using latest version.

@NawazKhanMd @courage-liberty I didn't find any solution for now.

@anvesh523
In the case of me, the problem is like the expo client.

@courage-liberty I was testing on emulator and mobile. On both devices it's not working.

@anvesh523
So.
Though because there was information to be good with the emulator, my issue may be different.

Guys i think theres a issue with react-native 0.42 and FlatList, I was in a development mode so choose the List component of native-base which was already added to the project

I you want to use the FlatList use the upgraded version of React-native as well as React too

in my case upgrading the react-native leads to dependency on a alpha version of react so I choose not to use a alpha version

now am using List of native-base instead of FlatList of React-native on same mentioned version of react-native

@anvesh523
I was able to work in the simulator.(Windows/Android)

There is information to be settled by version up.
https://github.com/facebook/react-native/issues/16090

For your information.

or if u are using 0.42 of react-native use ListView . ListView of 0.42 is changed to FlatList of 0.48

Person of expo saying "repairs it early" in Slack.
I wait for a while.

Try this:
import FlatList from 'FlatList';

It works for me.

Was this page helpful?
0 / 5 - 0 ratings