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

Comments

@chidimo
Copy link

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

This comment has been minimized.

Copy link
Member

commented Apr 11, 2019

@chidimo Hey,

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

@chidimo

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Apr 12, 2019

@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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Apr 14, 2019

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

thanks.

@Krizzu Krizzu closed this Apr 14, 2019

@quantumpotato

This comment has been minimized.

Copy link

commented May 11, 2019

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
Projects
None yet
4 participants
You can’t perform that action at this time.