React Native AsyncStorage

Ajith V
1 min readFeb 8, 2019

--

AsyncStorage is a simple key-value pair storage solution for a react-native Application.

1.Set data

First import AsyncStorage into the component

import { AsyncStorage } from ‘react-native’;

then

let user={ loggedInUser:'0',
mobileNo:'8086502009',
name:'V Ajith',
token:'8f5rw2h7r0s62gex'}
AsyncStorage.setItem( ‘user’, JSON.stringify(user) );

2.Fetch data

AsyncStorage.getItem('user').then(
userInfo => {console.log(userInfo)}).done();

3.Update Data

AsyncStorage.getItem('user')
.then(userInfo => {
let user= JSON.parse(userInfo);
user.name='Ajith',
AsyncStorage.setItem('user',JSON.stringify(user));
}).done();

--

--

Ajith V
Ajith V

Written by Ajith V

Technology enthusiast focussing on building high-performance hybrid solution

No responses yet