Louis
Louis

Reputation: 371

How to save data in react-native

I want to save data from a page of my react native project. From what I've searched, I must use :

import DefaultPreference from 'react-native-default-preference';
...
DefaultPreference.get('my key').then(function(value) {console.log(value)});
DefaultPreference.set('my key', 'my value').then(function() {console.log('done')});

if I want to save them locally . Howether when I use this inside my code, I got a blank page. What is the issue here? I didn't change anything in my original code apart from thes 3 linnes.

Upvotes: 0

Views: 648

Answers (1)

Ilya Ezy
Ilya Ezy

Reputation: 44

You can take this lib as more popular.

For example code:

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

await AsyncStorage.setItem(key, value);

const value = await AsyncStorage.getItem(key);
console.log('MY_VALUE===>', value);

await AsyncStorage.removeItem(key);

I hope, it is help you.

Upvotes: 1

Related Questions