synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
27 lines (26 loc) • 984 B
JavaScript
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