Why AsyncStorage getItem is returning null?

A. K. M. Nazmul Hassan picture A. K. M. Nazmul Hassan · Feb 16, 2018 · Viewed 8.7k times · Source
export const USER_KEY = "isLoggedIn";

export const phoneVerified = () => AsyncStorage.setItem(USER_KEY, 1);
export const userInfoVerified = () => AsyncStorage.setItem(USER_KEY, 2);

I have used the above functions to store the value and the below one to get the value.

export const isSignedIn = () => {
  return new Promise((resolve, reject) => {
    AsyncStorage.getItem(USER_KEY)
      .then(res => {
          console.log("from isSignedIn : "+res); //res is showing null.
        if (res !== null) {
          resolve(res);
        } else {
          resolve(0);
        }
      })
      .catch(err => reject(err));
  });
};

Why this always returns null? I was trying async/await but still getting null. I think somehow the data is not storing.

Answer

Vishu Bhardwaj picture Vishu Bhardwaj · Feb 16, 2018