How to use the react-native.AsyncStorage.getItem function in react-native

To help you get started, we’ve selected a few react-native examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AndroConsis / Food-Delivery-App / components / HotDeals.js View on Github external
fetchData() {
    let value = null;
    try {
      AsyncStorage.getItem("@MYSUPERSTORE", (err, result) => {
        if(result) {
          this.setState({
              dataSource: this.state.dataSource.cloneWithRows(JSON.parse(result)),
              isLoading: false,
            });

        } else {
          fetch(REQUEST_URL)
          .then((response) => response.json())
          .then((responseData) => {
            try {
              AsyncStorage.setItem("@MYSUPERSTORE", JSON.stringify(responseData));
            } catch (err) {
              // 
            }
            this.setState({
github getsentry / sentry-react-native / lib / raven-plugin.js View on Github external
reactNativePlugin._restorePayload = function() {
  var AsyncStorage = require('react-native').AsyncStorage;
  var promise = AsyncStorage.getItem(ASYNC_STORAGE_KEY).then(function(payload) {
    return JSON.parse(payload);
  })['catch'](function() {
    return null;
  });
  // Make sure that we fetch ASAP.
  var RCTAsyncSQLiteStorage = NativeModules.AsyncSQLiteDBStorage;
  var RCTAsyncRocksDBStorage = NativeModules.AsyncRocksDBStorage;
  var RCTAsyncFileStorage = NativeModules.AsyncLocalStorage;
  var RCTAsyncStorage =
    RCTAsyncRocksDBStorage || RCTAsyncSQLiteStorage || RCTAsyncFileStorage;
  if (RCTAsyncStorage.multiGet) {
    AsyncStorage.flushGetRequests();
  }

  return promise;
};
github ljunb / rn-beginner-guidance-decorator / index.js View on Github external
setupGuidance = async () => {
    try {
      const result = await AsyncStorage.getItem(this.guidanceCacheKey);
      if (!result) {
        this.setState({showGuidance: true});
        AsyncStorage.setItem(this.guidanceCacheKey, JSON.stringify({}));
      }
    } catch (e) {
      console.log(`[BeginnerGuidanceDecorator_${displayName}] setup guidance error: ${e}`);
    }
  };
github bonniee / learning-react-native / src / flashcards / src_checkpoint_04 / storage / decks.js View on Github external
async function read(key, deserializer) {
  try {
    let val = await AsyncStorage.getItem(key);
    if (val !== null) {
      let readValue = JSON.parse(val).map(serialized => {
        return deserializer(serialized);
      });
      return readValue;
    } else {
      console.info(`${key} not found on disk.`);
      return [];
    }
  } catch (error) {
    console.warn("AsyncStorage error: ", error.message);
  }
}
github gbuszmicz / firebase-auth-app / src / helpers / asyncStorage.js View on Github external
export function getUserToken() {
  return AsyncStorage
          .getItem('user')
          .then(parseJson);
}
github aws-amplify / amplify-js / packages / pushnotification / src / PushNotification.ts View on Github external
async _registerTokenCached(): Promise {
		const { appId } = this._config;
		const cacheKey = 'push_token' + appId;
		return AsyncStorage.getItem(cacheKey).then(lastToken => {
			if (lastToken) return true;
			else return false;
		});
	}
github HandlebarLabs / react-native-examples-and-tutorials / tutorials / complex-react-nav-with-guest-access / src / api / auth.js View on Github external
componentDidMount() {
    AsyncStorage.getItem('authData')
      .then((state) => {
        this.setState({
          ...JSON.parse(state),
          checkedAuth: true,
        });
      });
  }
github wangdicoder / react-native-Gank / js / dao / SettingsDataDAO.js View on Github external
return new Promise((resolve, reject) => {
            AsyncStorage.getItem(SHOW_THUMBNAIL, (error, result) => {
                if(!error && result){
                    if(result === 'true')
                        resolve(true);
                    else
                        resolve(false);
                }else{
                    reject(true);
                }
            });
        });
    }
github rotembcohen / pokerBuddyApp / containers / HomeView.js View on Github external
async joinGame(game_identifier){
		game = await utils.joinGame(game_identifier,this.state.token,this.state.user);
		if (game.error){
			this.setState({errorLabel:game.error});
			return;
		}
		let tutorialResponse = await AsyncStorage.getItem('@pokerBuddy:showTutorial');
		let showTutorial = (tutorialResponse === null) ? true : (tutorialResponse==='true');
		utils.resetToScreen(navigation,"GameView",{game: game,user: this.state.user,token:this.state.token,showTutorial:showTutorial});
	}