w7a*_*w7a 7 react-native flatlist
我正在构建一个 React Native 应用程序,但在使用 FlatList 时遇到了问题。我认为问题可能出在我尝试实现此操作的方式上,因此我使用了https://reactnative.dev/docs/flatlist中的示例代码并尝试自行运行它。
无论我如何尝试,我都会收到错误:
undefined 不是一个对象(评估 'props.getItem')
这是从 FlatList.js 第 450 行生成的。
该文件的第 449 行和 450 行是:
_checkProps(props: Props<ItemT>) {
const {
Run Code Online (Sandbox Code Playgroud)
这是来自与 React Native 捆绑在一起的 FlatList.js。
我使用的是 React Native 0.65.1。
这是我尝试运行的代码,它给了我错误:
import React from 'react';
import {
SafeAreaView,
View,
FlatList,
StyleSheet,
Text,
StatusBar,
} from 'react-native';
const DATA = [
{
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
title: 'First Item',
},
{
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
title: 'Second Item',
},
{
id: '58694a0f-3da1-471f-bd96-145571e29d72',
title: 'Third Item',
},
];
const Item = ({title}) => (
<View style={styles.item}>
<Text style={styles.title}>{title}</Text>
</View>
);
const ModalTrackSleep = () => {
const renderItem = ({item}) => <Item title={item.title} />;
return (
<SafeAreaView style={styles.container}>
<FlatList
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: StatusBar.currentHeight || 0,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 32,
},
});
export default ModalTrackSleep;
Run Code Online (Sandbox Code Playgroud)
我必须
'@babel/plugin-proposal-private-methods', '@babel/plugin-proposal-class-properties'
从我的 babel.config.js 中删除,然后 FlatList 再次工作。奇怪的是,FlatList 对我来说之前曾使用过那些 babel 插件。添加和删除react-native-geolocation模块后,这个问题开始出现在我身上。我还必须在类中重做我的私有方法和属性,这很不幸。
| 归档时间: |
|
| 查看次数: |
1975 次 |
| 最近记录: |