xtreme-ui
Version:
Collection of reusable components that can be used in web projects
14 lines (13 loc) • 436 B
JavaScript
"use client";
import { useState as n, useEffect as a } from "react";
import { getLocalState as i, setLocalState as u } from "../../utils/function/localStorage.js";
const f = (t, r) => {
const [e, s] = n(r ?? i(t));
return a(() => {
const o = () => u(t, e);
return window.addEventListener("beforeunload", o), () => window.removeEventListener("beforeunload", o);
}, [t, e]), [e, s];
};
export {
f as usePersistingState
};