import { onMounted, ref, watch } from "vue"; export function memorizeVar(key: string, defaultValue: T) { const variable = ref(defaultValue); onMounted(() => { const v = localStorage.getItem(key); if (v) variable.value = JSON.parse(v); }); watch(variable, (newValue) => { localStorage.setItem(key, JSON.stringify(newValue)); }); return { variable }; }