Konstantin Podlesny
Konstantin Podlesny

Reputation: 13

Can I get values from the local storage using Async Storage from React Native?

I am new at React Native. There is a native application written in Objective-C for iOS and Java for Android. My task is to add two more screens using React Native. The general solution is here.

The native code already uses a local storage to store permanent data (for example, data about an authorized user). At the same time, React Native uses Async Storage to handle permanent data.

Can I get values from the local storage using Async Storage from React Native?

Upvotes: 1

Views: 1893

Answers (2)

MortexaFarhadi
MortexaFarhadi

Reputation: 87

you need to use setItem() for set data and getItem() for get data. Set data:

await AsyncStorage.setItem('key', 'data');

Fetch data:

await AsyncStorage.getItem('key');

Asyncstorage in react native : https://facebook.github.io/react-native/docs/asyncstorage#docsNav

Upvotes: 2

DNA.h
DNA.h

Reputation: 863

As far as i know AsyncStorage is using Dictionary on iOS side and SQLite on android side. Both of which are not accessible in React Native side. You should write a bridge between native side and React Native to in order to allow passing of data between two sides, this https://github.com/sriraman/react-native-shared-preferences library is a good example, it allows React Native access local native shared prefrences and vice versa.

Upvotes: 0

Related Questions