how to store/save data in react native

React Native also have shared preferences this is npm command to get it: npm install react-native-shared-preferences --save. You can get complete details(how to set it up in react project) here: https://www.npmjs.com/package/react-native-shared-preferences


You can use React Native AsyncStorage for storing data to local storage of the device.

import { AsyncStorage } from 'react-native'

Use this to save data

AsyncStorage.setItem('key', 'value');

AsyncStorage accepts value as only string, so you may need to use stringify() before setting the value to AsyncStorage

And to retrieve data use

AsyncStorage.getItem('your key'); 

Example Code :

const KEY = 'USER_DATA'

let keyValue = { name: yogi }

AsyncStorage.setItem(KEY,keyValue);

AsyncStorage.getItem(KEY).then(asyncStorageRes => {
    console.log(JSON.parse(asyncStorageRes))
});