persist-ui
Version:
Universal input persistence for Vanilla, React, Vue, Astro, Next.js etc. with secure AES encryption.
23 lines (22 loc) • 636 B
JavaScript
import { ref, onMounted, onBeforeUnmount } from "vue";
import { persistUI } from "./core";
export function usePersistUI(key, opts) {
// No type constraint to support all element types
const elRef = ref(null);
let persistInstance = null;
onMounted(() => {
if (elRef.value) {
persistInstance = persistUI.attach(elRef.value, {
key,
...opts
});
}
});
onBeforeUnmount(() => {
// Only reset on unmount if explicitly requested
if (opts?.resetOnUnmount) {
persistInstance?.reset();
}
});
return elRef;
}