Files
rn-app/storage/index.js
2025-08-27 19:20:10 +08:00

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;