I am not so sure why this error is occurring. I have been trying to figure it out but have no idea how. The only thing new about my code is I am using react hooks and declared a state variable called allUsers.
import React, { useState, useEffect } from 'react'; import { API, graphqlOperation } from 'aws-amplify'
const [allUsers, setAllUsers] = useState([]);
listQuery = async () => {
const allUsers = await API.graphql(graphqlOperation(listUsers));
setAllUsers(allUsers);
console.log(JSON.stringify(allUsers, null, 2));
};
useEffect(() => {
listQuery();
},[]);
keyExtractor = (item, index) => index.toString()
renderItem = ({ item }) => (
<ListItem
username={item.username}
/>
)
return (
<FlatList
keyExtractor={this.keyExtractor}
data={allUsers}
renderItem={this.renderItem}
/>
)
}