Synchronous storage for React Native AsyncStorage.
yarn add sync-storage
# or# npm i --save sync-storageimportSyncStoragefrom'sync-storage';SyncStorage.set('foo','bar');constresult=SyncStorage.get('foo');console.log(result);// 'bar'Init prepares the SyncStorage to work synchronously, by getting all values for all keys previously saved on RN AsyncStorage. See the example:
constdata=awaitSyncStorage.init();console.log('AsyncStorage is ready!',data);Returns the value of key.
SyncStorage.get('foo');// 'bar'It saves the value on memory and on the AsyncStorage.
SyncStorage.set('foo','bar');SyncStorage.get('foo');// 'bar'It also returns a Promise for post verification.
SyncStorage.set('foo','bar').then(()=>{SyncStorage.get('foo');// 'bar'}).catch(error=>{console.log(error);});It removes the value from the memory and from the AsyncStorage.
SyncStorage.remove('foo');It also returns a Promise for post verification.
SyncStorage.remove('foo').then(()=>{SyncStorage.get('foo');// undefined}).catch(error=>{console.log(error);});returns an array from all the keys.
SyncStorage.set('foo','bar');SyncStorage.set('boo','baz');console.log(SyncStorage.getAllKeys())// ['foo', 'boo']