我编写了以下代码用于在平面列表中列出书籍,但它不起作用,它说“元素类型无效:需要一个字符串......”
FlatList 不起作用
书籍.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;