UNPKG

next-query-params

Version:

Convenient state management of query parameters in Next.js apps.

3 lines (2 loc) 751 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/router"),a=require("react"),r=/(?:(?![#\?])[\s\S])+/;function t(t){var s=t.children,n=t.shallow,o=void 0===n||n,h=e.useRouter(),u=h.asPath.match(r),c=u?u[0]:h.asPath,i=a.useMemo((function(){return"undefined"!=typeof window?h.isReady?window.location:{search:""}:{search:h.asPath.replace(r,"")}}),[h.asPath,h.isReady]);return s(a.useMemo((function(){function e(e){return function(a){var r=a.hash,t=a.search;e({pathname:h.pathname,search:t,hash:r},{pathname:c,search:t,hash:r},{shallow:o,scroll:!1})}}return{push:e(h.push),replace:e(h.replace),location:i}}),[i,c,h,o]))}exports.NextAdapter=a.memo(t); //# sourceMappingURL=next-query-params.cjs.production.min.js.map