I am currently getting data which is an array of objects from my local storage in following manner:
const [dataList, setDataList] = useState();
const getLocalItem = async () => {
try {
const jsonValue = await AsyncStorage.getItem('somekey');
const list = JSON.parse(jsonValue);
setDataList(list);
console.log("list: ", dataList);
return jsonValue != null ? JSON.parse(jsonValue) : null;
} catch (e) {
// error reading value
}
}
<TouchableOpacity onPress={getLocalItem}>
<Text>Get file</Text>
</TouchableOpacity>
Following is getting consoled:
list:
{0: {…}, 1: {…}, default: Array(2)}
0: {userId: 1, id: 1, title: "optio reprehenderit", body: " molestiae ut ut quas "}
1: {userId: 1, id: 2, title: "qui est esse", body: " aperiam non debitis possimus qui neque nisi nulla"}
default: (2) [{…}, {…}]
__proto__: Object
Now I am trying to map through this data to display it on my screen:
{
dataList?.map(function (item, index) {
return (
<Text>{item.userId}</Text>
);
})
}
But I am getting error:
dataList.map is not a function