You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import AsyncStorage from "@react-native-async-storage/async-storage";
  2. export const storeData = async (key, value) => {
  3. try {
  4. await AsyncStorage.setItem(key, value);
  5. } catch (e) {
  6. // error reading value
  7. }
  8. };
  9. export const storeObject = async (key, value) => {
  10. try {
  11. const jsonValue = JSON.stringify(value);
  12. await AsyncStorage.setItem(key, jsonValue);
  13. } catch (error) {
  14. console.log("Error storing object");
  15. }
  16. };
  17. export const getData = async (key) => {
  18. try {
  19. const value = await AsyncStorage.getItem(key);
  20. return value;
  21. } catch (e) {
  22. // error reading value
  23. }
  24. };
  25. export const getObjectData = async (key) => {
  26. try {
  27. const jsonValue = await AsyncStorage.getItem(key);
  28. return jsonValue !== null ? JSON.parse(jsonValue) : null;
  29. } catch (error) {}
  30. };
  31. export const removeData = async (key) => {
  32. try {
  33. await AsyncStorage.removeItem(key);
  34. } catch (e) {
  35. // error reading value
  36. }
  37. };
  38. export const clearAll = async () => {
  39. try {
  40. await AsyncStorage.clear();
  41. } catch (e) {}
  42. };