React Native Sync Storage

sajad abasi
1 min readApr 21, 2019

--

Are you tired of async storage that for saving any data even a simple integer to save state of application like logged in or not. so lets use sync storage.

we are going to use sync-storage library.

this library is great that uses async storage to save data asynchronously and uses memory to load and save data instantly synchronously, so we save data async to memory and use in app sync, so this is great.

# installation guid:

yarn add sync-storage

then we need to link react-native-async-storage:

react-native link @react-native-community/async-storage

usage is simple, we need an initialization when app boots up to load data to memory: we add this code to `App.js` file:

import SyncStorage from 'sync-storage';...async componentWillMount(): void {
const data = await SyncStorage.init();
console.log('AsyncStorage is ready!', data);
}

and usage in application:

import SyncStorage from 'sync-storage';...SyncStorage.set('foo', 'bar');

const result = SyncStorage.get('foo');
console.log(result); // 'bar'

that’s it, thank you for reading this article actually my first article :).

--

--