Reputation: 33
I'm trying to load data from firebase in react native into a table but I keep getting this error. It works fine with any two dimensional array but when I load the 2d array from firebase the error comes up.
async function get_passwords(user) {
const check_user = db.collection("users").doc(user);
const doc = await check_user.get();
const entries = Object.entries(doc.data());
return entries;
}
function InfoScreen({ navigation, route }) {
const { param1, param2 } = route.params;
const stated = {
tableHead: ["Info", "Password"],
tableData: [
["1", "2"],
["a", "b"],
["1", "2"],
["a", "b"],
],
};
let entries = get_passwords(param1);
return (
<View>
<Table>
<Row data={stated.tableHead} />
<Rows data={entries} />
</Table>
</View>
);
}
Upvotes: 0
Views: 3693
Reputation: 56
Since get_passwords is an async function, you need to use "await" for calling a function like
let entries = await get_passwords(param1);
const [entries, setEntries] = useState([]);
useEffect(() => {
getEntries(param1);
}, [param1]);
const getEntries = async (param) => {
const passwords = await get_passwords(param);
setEntries(passwords);
}
Upvotes: 1