How to use the @react-native-community/async-storage.multiSet 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 NordicMuseum / Nordic-Museum-Audio-Guide / v2 / src / appSettings.js View on Github external
export const setMuseumMode = async museumMode => {
  const setObj = [[APP_SETTINGS_KEYS.museumMode.key, boolToString(museumMode)]];

  try {
    await AsyncStorage.multiSet(setObj);
  } catch (e) {
    console.log(`Failed to save museumMode: ${e}`);
  }
};
github NordicMuseum / Nordic-Museum-Audio-Guide / v2 / src / appSettings.js View on Github external
export const setLocaleAndRTLForReset = async localeObj => {
  const setLocaleObj = Object.keys(localeObj).map(key => {
    const value =
      APP_SETTINGS_KEYS[key].type === APP_SETTINGS_TYPES.BOOL
        ? boolToString(localeObj[key])
        : localeObj[key];

    return [APP_SETTINGS_KEYS[key].key, value];
  });

  try {
    await AsyncStorage.multiSet(setLocaleObj);
  } catch (e) {
    console.log(`Failed to save locale: ${e}`);
  }
};
github HarishJangra / react-native-easy-starter / src / Services / AsyncStorage.js View on Github external
async function saveMultiValues(data) {
  const mappedValues = values.map((v, i) => {
    return [i, v];
  });
  try {
    await AsyncStorage.multiSet(mappedValues);
    return { success: true };
  } catch (e) {
    console.log("LOG_Async Storage access Failed", e);
    return { error: e };
  }
}
github pd4d10 / echojs-reader / app / context / auth.js View on Github external
async (_username, password) => {
      const json = await fetchWithAuth(
        `/login?username=${_username}&password=${password}`,
      );
      await AsyncStorage.multiSet([
        [STORAGE_KEYS.auth, json.auth],
        [STORAGE_KEYS.username, _username],
        [STORAGE_KEYS.secret, json.apisecret],
      ]);
      setAuth(json.auth);
      setUsername(_username);
      setSecret(json.apisecret);
    },
    [fetchWithAuth],
github crownstone / CrownstoneApp / js / router / store / Persistor.ts View on Github external
return new Promise((resolve, reject) => {
      if (keyValueWrites.length > 0) {
        let updatedKeys = [];
        for (let i = 0; i < keyValueWrites.length; i++) {
          updatedKeys.push(keyValueWrites[i][0]);
        }

        AsyncStorage.multiSet(keyValueWrites)
          .then(() => {
            this._updateUserKeyCache(updatedKeys);
            LOGd.store('Persistor: batch persisted', keyValueWrites);
          })
          .then( ()    => { resolve(); })
          .catch((err) => { reject(err); })
      }
      else {
        resolve();
      }
    })
  }
github callstack / async-storage / src / index.mobile.js View on Github external
  multiSet: kvPairs => AsyncStorage.multiSet(kvPairs),
  multiRemove: keys => AsyncStorage.multiRemove(keys),
github morrys / wora / packages / cache-persist / src / storage.native.ts View on Github external
multiSet: (items: string[][]) => {
            return AsyncStorage.multiSet(items);
        },
        setItem: (key: string, value: string): Promise => {
github jasonmerino / react-native-simple-store / src / index.js View on Github external
save(key, value) {
		if(!Array.isArray(key)) {
			return AsyncStorage.setItem(key, JSON.stringify(value));
		} else {
			var pairs = key.map(function(pair) {
				return [pair[0], JSON.stringify(pair[1])];
			});
			return AsyncStorage.multiSet(pairs);
		}
	},
github JetBrains / youtrack-mobile / src / components / storage / storage.js View on Github external
const pairsToRemove = Object.entries(storageState)
    .filter(([key, value]) => !hasValue(value));
  await AsyncStorage.multiRemove(pairsToRemove.map((([key]) => storageKeys[key])));

  const pairsToWrite = Object.entries(storageState)
    .filter(([key, value]) => value !== null && value !== undefined);

  if (pairsToWrite.length === 0) {
    log.debug('Storage state is empty, no actuall write has been done');
    return newState;
  }

  const pairs = pairsToWrite
    .map(([key, value]) => [storageKeys[key], hasValue(value) ? JSON.stringify(value) : value]);
  await AsyncStorage.multiSet(pairs);

  return storageState;
}