Async-storage: How do I add AsyncStorage to a project started with expo

Created on 11 Apr 2019  路  9Comments  路  Source: react-native-async-storage/async-storage

I want to use AsynStorage for a project which was started with expo init.

I added the library with yarn add @react-native-community/async-storage

When I try to import AsyncStorage in my project file like below, I get the error shown in the screenshot.

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

rnc-issue

When I try to run this command react-native link @react-native-community/async-storage as directed in the docs, I get the following error 'react-native' is not recognized as an internal or external command, operable program or batch file

How do I resolve this issue. I have tested on both my android phone and on a Genymotion virtual android device.

question

Most helpful comment

@mathiasseyfert Each major Expo release comes with upgraded RN version. You can see it here.

Async Storage on RN is deprecated, because it's been extracted to separate module, which is backward compatible. It's the same module, but lives elsewhere.

So I believe Next releases of expo will just move to use external modules, to not break compatibility.

thanks.

All 9 comments

@chidimo Hey,

You cannot add additional native modules to expo, unless you eject your project.

@chidimo Hey,

You cannot add additional native modules to expo, unless you eject your project.

I don't really understand what you mean. I'm a bit new to the world of expo and react-native.

I came here because the react-native docs states that its version of AsyncStorage is deprecated and that this should be used instead.

I see. Well, let me explain.

React Native allows you to extend itself with NativeModules - a library that's written in platform specific manner (Java/Kotlin for Android, ObjC/Swift for iOS), which comes with new features (accessed from Javascript). One example of such module is this Async Storage.

You said you're using Expo. It's still React Native, already extended with many many NativeModules, but in order to work the way it works, it's "closed", meaning you cannot add any additional native feature. In order to extend Expo, you have to "eject" it, meaning extract project into standard React Native app.

Okay. I believe I get it now.

So the only way I can get access to this AsyncStorage from @react-native-community/async-storage is either by ejecting to vanilla react-native so I can add extensions myself or for it to be added to expo by expo developers. Am I right?

This means that once I start with expo I'm stuck with the native modules expo provides until I eject. Right?

So if I eject i get to manually add vector icons and all other stuff coming from expo that are already part of my project. If that is the case, then I'll pass and just use the deprecated AsyncStorage that's part of react-native and hope the expo devs add up the newAsyncStorage` soon.

@chidimo Yes, you're right.

Expo comes with pretty nice and robust collection of native modules. Since RN is extracting it's internal Native Modules to external repos, it's just a matter of time when expo will adjust to this.

TBH, I wouldn't care much for the deprecation warning, it's just a hint that next minor RN release would not have Async Storage in-built.

thanks.

@Krizzu the problem is, if I start now with a new app and use the depreceated storage, what happens to my app after it is not included any more in the next RN release?

What are the easy to use alternatives for someone using expo to store information locally?

thank you

@mathiasseyfert Each major Expo release comes with upgraded RN version. You can see it here.

Async Storage on RN is deprecated, because it's been extracted to separate module, which is backward compatible. It's the same module, but lives elsewhere.

So I believe Next releases of expo will just move to use external modules, to not break compatibility.

thanks.

I hope this is all clear now, so closing it down.

thanks.

Oh I understand now, thanks for explaining

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rogueturnip picture rogueturnip  路  27Comments

dominiczaq picture dominiczaq  路  22Comments

santhanakrishnanstark picture santhanakrishnanstark  路  67Comments

mxmzb picture mxmzb  路  19Comments

josmithua picture josmithua  路  20Comments