我在 React 中编写了用于列出书籍的代码,但 FlatList 在我的代码中不起作用,我该如何解决?
I write code for listing books in react but FlatList don't work in my code,how can i solve it?
我写了下面的代码来在平面列表中列出书籍但是它不起作用,它说“元素类型是 invalid:expected 一个字符串....”
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;
在您的导入和 render()
函数中必须 FlatList
而不是 Flatlist
。
我写了下面的代码来在平面列表中列出书籍但是它不起作用,它说“元素类型是 invalid:expected 一个字符串....”
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;
在您的导入和 render()
函数中必须 FlatList
而不是 。Flatlist