From a7e97f33ae31dd2be1d7c04ecb8f2439ffebf921 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 21 Mar 2021 13:10:32 +0300 Subject: feat: add useQuery hook --- src/containers/ContractorPanel.tsx | 4 ++-- src/containers/Service/ServiceItem.tsx | 4 +++- src/hooks/useQuery.ts | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/hooks/useQuery.ts diff --git a/src/containers/ContractorPanel.tsx b/src/containers/ContractorPanel.tsx index 02e11ba..b68adec 100644 --- a/src/containers/ContractorPanel.tsx +++ b/src/containers/ContractorPanel.tsx @@ -14,13 +14,13 @@ const ContractorPanel: React.FC = ({ item, mutate }) => { - - diff --git a/src/containers/Service/ServiceItem.tsx b/src/containers/Service/ServiceItem.tsx index 22357c7..f833227 100644 --- a/src/containers/Service/ServiceItem.tsx +++ b/src/containers/Service/ServiceItem.tsx @@ -4,6 +4,7 @@ import { Formik } from 'formik'; import _ from 'lodash'; import Page, { Action } from '../Page'; import hooks from '../../hooks/useAPIClient'; +import useQuery from '../../hooks/useQuery'; import { post, patch, del } from '../../requests'; import ServiceContext from './ServiceContext'; @@ -14,6 +15,7 @@ interface Params { const ServiceItem: React.FC = () => { const service = useContext(ServiceContext); const history = useHistory(); + const query = useQuery(); const { id } = useParams(); const { data: item, mutate } = hooks[service.route].useItem(id); @@ -44,7 +46,7 @@ const ServiceItem: React.FC = () => { > {(!id || item) && ( diff --git a/src/hooks/useQuery.ts b/src/hooks/useQuery.ts new file mode 100644 index 0000000..b2cb628 --- /dev/null +++ b/src/hooks/useQuery.ts @@ -0,0 +1,9 @@ +import { useLocation } from 'react-router-dom'; + +const useQuery = () => { + const location = useLocation(); + const searchParams = new URLSearchParams(location.search); + return Object.fromEntries(searchParams); +}; + +export default useQuery; -- cgit v1.2.3