Initial commit

Created from https://vercel.com/new
This commit is contained in:
WaylonWalker 2021-12-08 18:25:42 +00:00
commit 4047a7ec23
378 changed files with 29334 additions and 0 deletions

34
hooks/usePageQuery.js Normal file
View file

@ -0,0 +1,34 @@
import { useMemo } from 'react';
import { useRouter } from 'next/router';
import { getQueryString } from 'lib/url';
export default function usePageQuery() {
const router = useRouter();
const { pathname, search } = location;
const query = useMemo(() => {
if (!search) {
return {};
}
const params = search.substring(1).split('&');
return params.reduce((obj, item) => {
const [key, value] = item.split('=');
obj[key] = decodeURIComponent(value);
return obj;
}, {});
}, [search]);
function resolve(params) {
const search = getQueryString({ ...query, ...params });
const { asPath } = router;
return `${asPath.split('?')[0]}${search}`;
}
return { pathname, query, resolve, router };
}