Hangry/app/config/asyncStorageHelper.js

45 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-02-27 16:19:55 +08:00
import {AsyncStorage} from 'react-native'
import React, { Component } from 'react';
export default class AsyncStorageHelper extends Component{
async saveData(key, value) {
try {
await AsyncStorage.setItem(key, JSON.stringify(value));
} catch (error) {
console.error('save error'+ error.message);
}
}
async saveString(key, value) {
try {
await AsyncStorage.setItem(key, value);
} catch (error) {
console.error('save error'+ error.message);
}
}
async getData(key, callback) {
try {
var value = await AsyncStorage.getItem(key).then(
(values) => {
callback(values);
}
)
} catch (error) {
// console.error('get error');
}
}
async removeItemValue(key) {
try {
await AsyncStorage.removeItem(key);
return true;
}
catch (exception) {
console.log(exception)
return false;
}
}
}