26 lines
534 B
JavaScript
26 lines
534 B
JavaScript
// storage.js
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
const Storage = {
|
|
setItemAsync(key, value) {
|
|
return AsyncStorage.setItem(key, JSON.stringify(value || {}));
|
|
},
|
|
|
|
getItemAsync(key) {
|
|
return new Promise(resolve=>{
|
|
AsyncStorage.getItem(key).then(value=>{
|
|
resolve(value ? JSON.parse(value) : null)
|
|
})
|
|
})
|
|
},
|
|
|
|
removeItemAsync(key) {
|
|
return AsyncStorage.removeItem(key)
|
|
},
|
|
|
|
clearAllAsync() {
|
|
return AsyncStorage.clear();
|
|
}
|
|
};
|
|
|
|
export default Storage; |