Home » React Native AsyncStorage Methods

React Native AsyncStorage Methods

by Online Tutorials Library

AsyncStorage Methods

There are various methods of React Native AsyncStorage class which are described below:

Methods

setItem()

The setItem() sets the value for a key and invokes a callback upon compilation. It returns a Promise object.

getItem()

The getItem() fetches an item from a key and invokes a callback upon completion. It returns a Promise object.

removeItem()

The removeItem() removes an item for a key and invokes a callback upon compilation. It returns a Promise object.

mergeItem()

The mergeItem() merges the existing key’s value with the input value and assuming both values are stringified JSON. It returns a Promise object.

NOTE: This method is not supported by all the native implementations.

clear()

The clear() method erases all AsynchStorage from all clients, libraries, etc. It is suggested that don’t call this, instead of this you may use removeItem or multiRemove to clear only your app’s keys. It returns the Promise object.

getAllKeys()

It gets all the keys which are known to your app, for all callers, libraries, etc. It returns a Promise object.

flushGetRequests()

It flushes any pending request using a single batch call to get the data.

multiGet()

This method allows you to batch fetching of items given in an array of key inputs. The callback method will be invoked with an array of corresponding key-value pairs found:

The method returns a Promise object.

multiSet()

This method is used as a batch operation to store multiple key-value pairs. After the completion of operations, you will get a single callback with any errors:

The method returns a Promise object.

multiRemove()

This method calls the batch deletion of all keys in the key array. It returns a Promise object.

multiMerge()

It executes the batch of operation to merge existing and new values for a given set of keys. It assumes that the values are stringified JSON. It returns a Promise object.

Note: This method is not supported by all native implementations.


Next Topic#

You may also like