diff --git a/frontend/src/hooks/useQueryParam.ts b/frontend/src/hooks/useQueryParam.ts index 8f1abc12..0f027f7f 100644 --- a/frontend/src/hooks/useQueryParam.ts +++ b/frontend/src/hooks/useQueryParam.ts @@ -51,8 +51,8 @@ export const useQueryParam = () => { [updateUrl], ); const getQueryParam = useCallback( - (key: T): T | undefined => { - return queryParams[key] as T; + (key: T): QueryParams[T] | undefined => { + return queryParams[key] as QueryParams[T]; }, [queryParams], ); diff --git a/frontend/src/hooks/useSearch.ts b/frontend/src/hooks/useSearch.ts index eed31e4c..9cb3e8ec 100644 --- a/frontend/src/hooks/useSearch.ts +++ b/frontend/src/hooks/useSearch.ts @@ -12,6 +12,7 @@ import { ChangeEvent, useEffect, useRef, useState } from "react"; import { TBuildInitialParamProps, TBuildParamProps, + TFilterStringFields, TParamItem, } from "@/types/search.types"; @@ -23,13 +24,11 @@ const buildOrParams = ({ params, searchText }: TBuildParamProps) => ({ })), }); const buildILikeParams = ({ params, searchText }: TBuildParamProps) => - params?.reduce( - (acc, field) => ({ - ...acc, - [field]: { contains: searchText }, - }), - {}, - ); + params?.reduce((acc, field) => { + acc[field] = { contains: searchText }; + + return acc; + }, {} as Record, unknown>); const buildEqInitialParams = ({ initialParams, }: TBuildInitialParamProps) => @@ -75,11 +74,15 @@ export const useSearch = ({ }, [searchText]); useEffect(() => { - if (queryParamKey && queryParamValue !== searchText) { - setSearchText(queryParamValue || ""); + if ( + queryParamKey && + queryParamValue !== searchText && + queryParamValue !== undefined + ) { + setSearchText(queryParamValue.toString() || ""); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [queryParamValue]); + }, [queryParamValue, queryParamKey]); const onSearch = debounce( async (e: ChangeEvent | string) => {