import { ref, watchEffect } from "vue";
type UseStorageReturn<T> = {
  storedValue: T;
};
export function useStorage<T>(
  key: string,
  defaultValue: T
): UseStorageReturn<T> {
  const storedValue = ref<T>(uni.getStorageSync(key) || defaultValue);
  watchEffect(() => {
    uni.setStorageSync(key, storedValue.value);
  });
  return storedValue;
}

