Search code examples
reactjsreact-nativereact-native-flatlistreact-flatlist

I write code for listing books in react but FlatList don't work in my code,how can i solve it?


I write the following code for listing books in a flat list but it doesn't work,It's says that "Element type is invalid:expected a string...."

FlatList don't work Blockquote

Books.js

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

class Books extends React. Component{

constructor(props){
    super(props)
    this.state={
        DATA:[
            {
                id: '1',
                title: 'First Item',
              },
              {
                id: '2',
                title: 'Second Item',
              },
              {
                id: '3',
                title: 'Third Item',
              },
        ]
    }
};
renderItemBook=({item})=>{
    return(
        <View>
            <Text>
                {item.title}
            </Text>
    </View>
    )
};
render(){
    return(
        <Flatlist
        data={this.state.DATA}
        renderItem={this.renderItemBook}
        keyExtractor={(item)=>item.id}
    />
    )
}
};
export default Books;

Solution

  • It must be FlatList not Flatlist in your imports and render() function.