我正在构建一个 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 …Run Code Online (Sandbox Code Playgroud)