How to use the @react-native-community/async-storage.multiGet function in @react-native-community/async-storage

To help you get started, we’ve selected a few @react-native-community/async-storage 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 pd4d10 / echojs-reader / app / context / auth.js View on Github external
(async () => {
      // For debugging
      // const storage = await AsyncStorage.multiGet(
      //   await AsyncStorage.getAllKeys(),
      // )
      // console.log(JSON.stringify(storage, null, 2))

      const [
        [, _auth],
        [, _username],
        [, _secret],
      ] = await AsyncStorage.multiGet([
        STORAGE_KEYS.auth,
        STORAGE_KEYS.username,
        STORAGE_KEYS.secret,
      ]);
      // console.log(_auth, _username, _secret)
      setAuth(_auth);
      setUsername(_username);
      setSecret(_secret);
      setReady(true);
    })();
  }, []);
github BrightID / BrightID / BrightID / src / versions / v0.js View on Github external
export const getConnections = async (allKeys: string[]) => {
  try {
    const connectionKeys = allKeys.filter(
      (val) =>
        val !== 'userData' &&
        !val.startsWith('App:') &&
        !val.startsWith('store'),
    );
    console.log('connectionKeys', connectionKeys);
    const storageValues = await AsyncStorage.multiGet(connectionKeys);
    const connections = storageValues.map((val) => JSON.parse(val[1]));
    // update redux store
    store.dispatch(setConnections(connections));
    store.dispatch(defaultSort());

    // sort connections
  } catch (err) {
    err instanceof Error ? console.warn(err.message) : console.log(err);
    throw new Error('unable to recover connections');
  }
};
github crownstone / CrownstoneApp / js / router / store / Persistor.ts View on Github external
_step2(keyList : string[]) {
    LOGd.store("Persistor: Hydration v2 Step2, getting data from keys.");
    return AsyncStorage.multiGet(keyList)
      .catch((errorArray : asyncMultiError[]) => {
        LOGw.store("Persistor: Hydration v2 Step2, error while getting data.");
        // attempt to get the historical version of failed keys.
        if (Array.isArray(errorArray)) {
          // handle all errors
          let failedKeys = [];
          errorArray.forEach((err : asyncMultiError) => {
            let key = err.key;
            LOGw.store("Persistor: Hydration v2 Step2, problem getting key in step 2:", key, err.message);
            failedKeys.push(key);
          });

          // clear broken keys.
          LOGd.store("Persistor: Hydration v2 Step2, removing failing keys.", failedKeys);
          return AsyncStorage.multiRemove(failedKeys)
            .catch((err) => {
github NordicMuseum / Nordic-Museum-Audio-Guide / v2 / src / appSettings.js View on Github external
export const getAppSettings = async () => {
  let appSettings;
  const settingKeys = Object.keys(APP_SETTINGS_KEYS);

  try {
    const values = await AsyncStorage.multiGet(settingKeys);

    appSettings = values.reduce((acc, [key, value]) => {
      acc[key] = appSettingsTypeParse(APP_SETTINGS_KEYS[key].type, value);
      return acc;
    }, {});
  } catch (e) {
    console.log(`Failed to get app settings: ${e}`);
    return;
  }

  return appSettings;
};
github ShaMan123 / react-native-math-view / src / android / deprecated / MathProvider.js View on Github external
.then((cacheKeys) => {
                return AsyncStorage
                    .multiGet(cacheKeys)
                    .then((response) => {
                        return response.map((value) => {
                            const [storageKey, data] = value;
                            return JSON.parse(data);
                        });
                    });
            });
    }
github callstack / async-storage / src / index.mobile.js View on Github external
  multiGet: keys => AsyncStorage.multiGet(keys),
  mergeItem: key => AsyncStorage.mergeItem(key),
github jasonmerino / react-native-simple-store / src / index.js View on Github external
get(key) {
		if(!Array.isArray(key)) {
			return AsyncStorage.getItem(key).then(value => {
				return JSON.parse(value);
			});
		} else {
			return AsyncStorage.multiGet(key).then(values => {
				return values.map(value => {
					return JSON.parse(value[1]);
				});
			});
		}
	},
github kiwicom / mobile / packages / relay / src / CacheManager.js View on Github external
restoreCache = async () => {
    let cacheSize = 0;
    const keys = await AsyncStorage.getAllKeys();
    const cachedData = await AsyncStorage.multiGet(keys.filter(key => key.startsWith(CACHE_KEY)));
    const keysToDelete = [];
    cachedData.forEach(([key, data]) => {
      const parsedData = JSON.parse(data);

      if (parsedData == null) {
        keysToDelete.push(key);
        return;
      }

      const { queryID, variables } = JSON.parse(key.substring(CACHE_KEY.length));

      if (this.isCurrent(parsedData.fetchTime) && cacheSize < CACHE_SIZE) {
        this.cache.set(queryID, variables, parsedData.payload);
        cacheSize++;
      } else {
        keysToDelete.push(key);
github wkl007 / GitHubPopular / src / utils / cache / FavoriteDao.js View on Github external
this.getFavoriteKeys().then(keys => {
        let items = []
        if (keys) {
          AsyncStorage.multiGet(keys, (err, stores) => {
            try {
              stores.map((result, i, store) => {
                let key = store[i][0]
                let value = store[i][1]
                if (value) items.push(JSON.parse(value))
              })
              resolve(items)
            } catch (e) {
              reject(e)
            }
          })
        } else {
          resolve(items)
        }
      }).catch((err) => {
        reject(err)