-
Notifications
You must be signed in to change notification settings - Fork 1
/
AsyncStorage.ts
60 lines (55 loc) · 1.25 KB
/
AsyncStorage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import AsyncStorage from "@react-native-async-storage/async-storage";
/**
* Removes item from AsyncStorage
* Takes in the key of the item to be removed from AsyncStorage
*/
export const removeValue = async (key: string) => {
try {
await AsyncStorage.removeItem(key);
} catch (e) {
console.log(e);
}
};
/**
* Stores item in AsyncStorage
* Takes in the key of the item to be stored
* Takes in the value of the item to be stored
*/
export const storeData = async (key: string, value: any) => {
try {
await AsyncStorage.setItem(key, value);
} catch (e) {
console.log(e);
}
};
/**
* Returns the String value of an item in AsyncStorage
* Takes in the key of the item to be returned
*/
export const getKeyString = async (key: string) => {
try {
let value = await AsyncStorage.getItem(key);
if (value !== null) {
return value;
}
} catch (e) {
console.log(e);
}
};
export const getKeyJSON = async (key: string) => {
try {
let value = await AsyncStorage.getItem(key);
if (value !== null) {
return JSON.parse(value);
}
} catch (e) {
console.log(e);
}
};
export const removeData = async (key: string) => {
try {
await AsyncStorage.removeItem(key);
} catch (e) {
console.log(e);
}
};