UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

27 lines (26 loc) 984 B
import { useCallback as i, useState as w, useEffect as c } from "react"; const v = (t) => { const s = i( () => new URLSearchParams( typeof window < "u" ? window.location.search : "" ).get(t), [t] ), [o, a] = w(s); return c(() => { const e = () => { a(s()); }; return window.addEventListener("popstate", e), window.addEventListener("pushstate", e), window.addEventListener("replacestate", e), () => { window.removeEventListener("popstate", e), window.removeEventListener("pushstate", e), window.removeEventListener("replacestate", e); }; }, []), [o, (e) => { const n = new URLSearchParams(window.location.search); e ? n.set(t, e) : n.delete(t); const r = `${window.location.pathname}?${n.toString()}`; window.history.pushState(window.history.state ?? {}, "", r), a(e), window.dispatchEvent(new Event("pushstate")); }]; }; export { v as useNativeSearchParams }; //# sourceMappingURL=useNativeSearchParams.js.map