Redux-persist: AsyncStorage extracted from react-native core

Created on 27 Mar 2019  路  23Comments  路  Source: rt2zz/redux-persist

I upgraded to React Native 0.59 and am now seeing this warning message:

Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage

Most helpful comment

For me it's working like this:

import AsyncStorage from '@react-native-community/async-storage';

const persistConfig = {
  timeout: 0,
  key: 'roott',
  storage: AsyncStorage,
  blacklist: []
};

All 23 comments

@chris-feist I too upgraded today and redux-persist stopped working on iOS. Does it work for you?

You can use this patch to make it working again

diff --git a/node_modules/redux-persist/src/storage/index.native.js b/node_modules/redux-persist/src/storage/index.native.js
index 641e10f..6dcc965 100644
--- a/node_modules/redux-persist/src/storage/index.native.js
+++ b/node_modules/redux-persist/src/storage/index.native.js
@@ -1,6 +1,6 @@
 // @noflow
 /* eslint-disable */

-import { AsyncStorage } from 'react-native'
+import AsyncStorage from '@react-native-community/async-storage';

 export default AsyncStorage

Yeah, it still works and is just a warning message. I just posted this issue as something that will need to be resolved in the future

It fails for me when testing without debug mode or release builds

Same as @chris-feist for me, works on debug mode on and off. I do get a warning but not a failure. As far as I can tell from react-native code this has not been removed yet:

https://github.com/facebook/react-native/blob/master/Libraries/react-native/react-native-implementation.js#L196

Interested to know why it's failing for you though.

Honestly I don't get why it fails for me either. It fails only on iOS

Looks like @rt2zz has a release coming: https://github.com/rt2zz/redux-persist/releases/tag/v6.0.0-pre1

For me it's working like this:

import AsyncStorage from '@react-native-community/async-storage';

const persistConfig = {
  timeout: 0,
  key: 'roott',
  storage: AsyncStorage,
  blacklist: []
};

When I use

import AsyncStorage from '@react-native-community/async-storage';
const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
  ...
};

I got error saying [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

Does anyone has the same issue?

@stacywang0601 Are you on latest RN?

@FRizzonelli I'm on version 0.59

Did you run _react-native link_ after installing?

Edit: Also, are you on Expo or did you eject? Because you need to eject to link libs

@FRizzonelli . Seems like I didn't link it successfully. Thanks!

When I use

import AsyncStorage from '@react-native-community/async-storage';
const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
  ...
};

I got error saying [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

Does anyone has the same issue?

Check you have installed the async storage with npm, restart your npm server and restart your emulator.

Hello, i am getting the same error does anyone find the solution with expo?

@MiltonBO I used that . Didn't works .

Every library that use AsyncStorage must be changed to import from community library. When you let a library to import from 'react-native' that warning will happens.

I found a lot of libraries using AsyncStorage, check what library is having the problem. If you changed this for redux-persist, could be another library the problem.

Don't forget to restart your metro server and reinstall the mobile app in your device.

When I use

import AsyncStorage from '@react-native-community/async-storage';
const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
  ...
};

I got error saying [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

Does anyone has the same issue?

I'm having the same error, I'm on version 0.59, I already:

  • run react-native link @react-native-community/async-storage
  • run react-native run-android
  • restart emulator

@HugoLiconV pod install maybe ?

@HugoLiconV pod install maybe ?

The problem was that it wasn't linking correctly, so I had to do it manually

i was using Async for session management and the Async removeItem was reporting success but failing to delete the item (user stayed logged in). When I removed redux-persist the message disappeared (obviously) and Async started working again.

Another comment suggested that you can't include both (one from library and one from a custom view) and expect consistent results.

I'm having this issue on iOS ... it doesn't. persist the state with AsyncStorage.

If I call @RNC/AsyncStorage independently from redux-persist, the data is actually stored.

Was this page helpful?
0 / 5 - 0 ratings