UNPKG

persist-ui

Version:

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

25 lines (24 loc) 708 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePersistUI = usePersistUI; const react_1 = require("react"); const core_1 = require("./core"); function usePersistUI(key, opts) { // Support all form element types const ref = (0, react_1.useRef)(null); (0, react_1.useEffect)(() => { if (!ref.current) return; const persist = core_1.persistUI.attach(ref.current, { key, ...opts }); // Only reset on unmount if explicitly requested return () => { if (opts?.resetOnUnmount) { persist.reset(); } }; }, [key, opts]); return ref; }