Now i created an async function getUsers which returns a promise with the correct data. Then, I tried retrieving the data in a form of array by using .then(). However, the data is empty when I call getUsers() in get().
getUsers = async () => {
try {
const users = await AsyncStorage.getItem("@FriendBook:Users");
if (users !== null) {
return JSON.parse(users);
}
return [];
} catch (error) {
console.log("Unable to load users", error);
}
};
get = () => {
var p = getUsers();
var users = [];
p.then((res) => {
users = res;
});
return users;
};