Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - How to see what's stored in AsyncStorage?

I save some items to AsyncStorage in React Native and I am using chrome debugger and iOS simulator.

Without react native, using regular web development localStorage, I was able to see the stored localStorage items under Chrome Debugger > Resources > Local Storage

Any idea how can I view the React Native AsyncStorage stored items?

like image 989
Wonka Avatar asked Jul 25 '16 14:07

Wonka


People also ask

Where is the data stored in AsyncStorage?

On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files. On Android, AsyncStorage will use either RocksDB or SQLite based on what is available.

How do I see AsyncStorage in React Native debugger?

React Native Debugger has this built in. Just call showAsyncStorageContentInDev() in the RND console and you'll be able to see a dump of your app's storage.

How do you store value in AsyncStorage in React Native?

For store value in asyncstorage, React native asyncstorage provide setItem() method, it will expect storage key and value . Check below examples to store string, number, or object in AsyncStorage. To store number in AsyncStorage we have to first convert to string using toString() method.


3 Answers

React Native Debugger has this built in.

Just call showAsyncStorageContentInDev() in the RND console and you'll be able to see a dump of your app's storage.

like image 50
Jayden Avatar answered Oct 16 '22 20:10

Jayden


You can use reactotron i think it has Async Storage explorer ;) https://github.com/infinitered/reactotron

enter image description here

like image 52
Fareed Alnamrouti Avatar answered Oct 16 '22 21:10

Fareed Alnamrouti


Following should work,

AsyncStorage.getAllKeys((err, keys) => {
  AsyncStorage.multiGet(keys, (error, stores) => {
    stores.map((result, i, store) => {
      console.log({ [store[i][0]]: store[i][1] });
      return true;
    });
  });
});
like image 22
skantus Avatar answered Oct 16 '22 20:10

skantus