嘿,我试图在Flatlist中显示来自API的数据,但我不断收到以下错误消息:“不变违规:元素类型无效:预期为内置字符串(对于内置组件)或类/函数复合组件,但未定义。...检查“ UsersScreen”的渲染方法
我不确定代码的哪一部分会导致此错误
import { API, graphqlOperation } from 'aws-amplify'
import { Text, View, Flatlist } from 'react-native'
const listUsers = `query listUsers {
listUsers {
username
}
}`;
class UsersScreen extends Component {
listQuery = async () => {
console.log('listing Users');
const allUsers = await API.graphql(graphqlOperation(listUsers));
alert(JSON.stringify(allUsers));
};
render() {
return(
<Flatlist
data={listUsers}
renderItem={({ item }) => (
<View>
<Text>{item.username}</Text>
</View>
)}
/>
)
}
}
export default UsersScreen;
答案 0 :(得分:0)
您缺少组件的导入:
import { Component } from 'react';