Skip to content

Files

Latest commit

e83f7ac · Mar 8, 2021

History

History
20 lines (16 loc) · 704 Bytes

Storage.md

File metadata and controls

20 lines (16 loc) · 704 Bytes

AsyncStorage.clear() errors on iOS but not Android.

AsyncStorage.getAllKeys().then(AsyncStorage.multiRemove) errors on Android but not iOS.

import { Platform } from "react-native";
import AsyncStorage from "@react-native-community/async-storage";

const asyncStorageKeys = await AsyncStorage.getAllKeys();
if (asyncStorageKeys.length > 0) {
  if (Platform.OS === "android") {
    await AsyncStorage.clear();
  }
  if (Platform.OS === "ios") {
    await AsyncStorage.multiRemove(asyncStorageKeys);
  }
}

Storing and Retrieving Objects using AsyncStorage in React Native