how to remove an item from AsyncStorage in react-native

后端 未结 7 2960
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 21:56

how to remove an item from AsyncStorage? right now I am trying this code

AsyncStorage.removeItem(\'userId\');

but this is not working for me.

相关标签:
7条回答
  • 2021-02-19 22:38

    This is the framework code for AsyncStorage.removeItem:

    removeItem: function(
     key: string,
     callback?: ?(error: ?Error) => void
    ): Promise {
     return new Promise((resolve, reject) => {
      RCTAsyncStorage.multiRemove([key], function(errors) {
        var errs = convertErrors(errors);
        callback && callback(errs && errs[0]);
        if (errs) {
          reject(errs[0]);
        } else {
          resolve(null);
        }
      });
     });
    }
    

    As you can see above it requires the key(Which is name of the item you set in asyncstorage that you want to delete) and a callback function. Make sure you have the correct key and the correct params and it should work fine.

    0 讨论(0)
提交回复
热议问题