0
export async function getLessons() {
const group = await AsyncStorage.getItem('@group');
let data;
 await database()
.ref(`PI20/0/days`)
.once('value')
.then(snapshot => {
  console.log(snapshot.val());
  data = snapshot.val();
})

This one works fine

useEffect(() => {
console.log(getGroupList());
}, [])

async function getGroupList() {
let data;
database()
  .ref(`PI20/0/days`)
  .once('value')
  .then(snapshot => {
    console.log(snapshot.val());
    data = snapshot.val();
  })

 return data
 }

And here, .then() is skipped. Function can be called and works untill the end, the route is good, but I can't get the snapshot because .then() is just skipped.Why could be that?

Sneikso34
  • 31
  • 1
  • 6
  • `then` isn't skipped, it just gets called *after* you've returned the value of `data` (while `data` is still `undefined`) because you aren't awaiting the promise. – Quentin Sep 08 '22 at 14:01
  • @Quentin I tried to add ```await``` but it didn't help – Sneikso34 Sep 08 '22 at 14:19

0 Answers0