rn-async-storage icon indicating copy to clipboard operation
rn-async-storage copied to clipboard

Add removeItem method to the API

Open adam-s opened this issue 6 years ago • 3 comments

AsyncStorage.removeItem() doesn't exist for Android. Can the API include this and the other methods? I've been using AsyncStorage.set('key', null) as the work around.

getItem
setItem
removeItem
mergeItem
clear
getAllKeys
flushGetRequests
multiGet
multiSet
multiRemove
multiMerge

adam-s avatar May 14 '18 17:05 adam-s

soon will coming birthday of this bug https://github.com/facebook/react-native/issues/14101 I will try to implement all methods until 22 May

gadfil avatar May 15 '18 07:05 gadfil

Adding the following to java/org/gamega/RNAsyncStorageModule.java will add removeItem

/**
  * Write string value by key
  * @param key
  */
 @ReactMethod
 public void removeItem(String key, Promise promise){
     try {
         SharedPreferences sharedPref = getCurrentActivity().getPreferences(Context.MODE_PRIVATE);
         SharedPreferences.Editor editor = sharedPref.edit();
         editor.remove(key);
         editor.commit();
         promise.resolve(null);
     }catch (Exception e){
         promise.reject(e);
         e.printStackTrace();
     }
 }

jonathanRinciari avatar Jul 09 '18 14:07 jonathanRinciari

It looks like this library's removeItem is fixed in Github but npm is not updated.

brianephraim avatar Aug 15 '18 19:08 brianephraim