Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add AsyncStorage to a project started with expo #72

Closed
chidimo opened this issue Apr 11, 2019 · 9 comments
Closed

How do I add AsyncStorage to a project started with expo #72

chidimo opened this issue Apr 11, 2019 · 9 comments
Labels
question General question about usage

Comments

@chidimo
Copy link

chidimo commented Apr 11, 2019

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.

@krizzu
Copy link
Member

krizzu commented Apr 11, 2019

@chidimo Hey,

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

@chidimo
Copy link
Author

chidimo commented Apr 11, 2019

@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.

@krizzu
Copy link
Member

krizzu commented Apr 11, 2019

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.

@chidimo
Copy link
Author

chidimo commented Apr 11, 2019

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 new AsyncStorage` soon.

@krizzu krizzu added the question General question about usage label Apr 12, 2019
@krizzu
Copy link
Member

krizzu commented Apr 12, 2019

@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.

@mathiasseyfert
Copy link

@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

@krizzu
Copy link
Member

krizzu commented Apr 12, 2019

@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.

@krizzu
Copy link
Member

krizzu commented Apr 14, 2019

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

thanks.

@krizzu krizzu closed this as completed Apr 14, 2019
@quantumpotato
Copy link

Oh I understand now, thanks for explaining

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question about usage
Projects
None yet
Development

No branches or pull requests

4 participants