I have been trying to work this out for a VERY long time, but I just cannot. I do not understand why an array, whose contents I console.log, and clearly see it is not empty, and has the elements I want in it, is not being rendered on the page when I run my react native app. My code is below, please help guys
import React, { useEffect } from "react";
import AsyncStorage from "@react-native-community/async-storage";
import { View, Text } from "react-native";
export default function PaymentsScreen() {
const [renderedData, setRenderedData] = React.useState(new Array<string>());
const getData = async () => {
try {
const keys = await AsyncStorage.getAllKeys();
const result = await AsyncStorage.multiGet(keys);
return result;
} catch (e) {
console.log(e);
}
};
async function parseData() {
const payments = await getData();
if (payments) {
const res = payments
.filter((e: any[]) => e[1] && e.includes('{'))
.map((e: any[]) => e[1]);
setRenderedData(res);
}
return renderedData;
}
React.useEffect(() => {
parseData()
});
return (
<View>
{renderedData.map(data => <Text>{data}</Text> )}
</View>
);
}