import AsyncStorage from '@react-native-async-storage/async-storage';

export const setStorageData = async (key: string, value: any) => {
	try {
		await AsyncStorage.setItem(key, JSON.stringify(value));
	} catch (e) {
		// saving error
		return null;
	}
};

export const getStorageData = async (key: string) => {
	try {
		const value = await AsyncStorage.getItem(key);
		if (value !== null) {
			return JSON.parse(value);
		}
	} catch (e) {
		return null;
	}
};

export const removeStorageData = async (key: string) => {
	const result = await AsyncStorage.removeItem(key).catch(() => {
		return null;
	});
	return result;
};
