Skip to content
React native AsyncStorage example
JavaScript Objective-C Python Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__
android
ios
.babelrc
.buckconfig
.flowconfig
.gitattributes
.gitignore
.watchmanconfig
README.md
app.json
index.android.js
index.ios.js
package.json
yarn.lock

README.md

react-native-AsyncStorage

React native AsyncStorage example

Installation

Clone repo

$ git clone https://github.com/pradeep1991singh/react-native-AsyncStorage.git

Run

$ cd react-native-AsyncStorage

# run ios app
$ react-native run-ios

# run android app
$ react-native run-android

Saving/Retrieving Data

As AsyncStorage name suggests its an asynchronous storage which returns Promise object.

Persisting data

For persisting data in react app there is AsyncStorage.setItem method as we have localStorage.setItem in localStorage. setItem takes two parameters as key-value pair. e.g. -

try {
  await AsyncStorage.setItem('@MySuperStore:key', 'hi there');
} catch (error) {
  // Error saving data
  console.log(error);
}

Retrieving data

For getting saved data back there is AsyncStorage.getItem method which takes one parameter(key-name). e.g. -

try {
  const value = await AsyncStorage.getItem('@MySuperStore:key');
  console.log(value); // hi there
} catch (error) {
  console.log(error);
}

Remove saved key

For removing Item for a key there is AsyncStorage.removeItem method which takes one parameter(key-name). e.g. -

try {
  await AsyncStorage.removeItem('@MySuperStore:key');
} catch (error) {
  console.log(error);
}
You can’t perform that action at this time.