UNPKG

persist-ui

Version:

Universal input persistence for Vanilla, React, Vue, Astro, Next.js etc. with secure AES encryption.

26 lines (25 loc) 756 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePersistUI = usePersistUI; const vue_1 = require("vue"); const core_1 = require("./core"); function usePersistUI(key, opts) { // No type constraint to support all element types const elRef = (0, vue_1.ref)(null); let persistInstance = null; (0, vue_1.onMounted)(() => { if (elRef.value) { persistInstance = core_1.persistUI.attach(elRef.value, { key, ...opts }); } }); (0, vue_1.onBeforeUnmount)(() => { // Only reset on unmount if explicitly requested if (opts?.resetOnUnmount) { persistInstance?.reset(); } }); return elRef; }