From edbc9f686f66a1ec681a14dbf79392f0dbaa9904 Mon Sep 17 00:00:00 2001 From: lifeparticle Date: Sun, 24 Sep 2023 20:42:18 +1000 Subject: [PATCH] tidy --- ui/src/lib/utils/hooks/useParamsValue.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/ui/src/lib/utils/hooks/useParamsValue.ts b/ui/src/lib/utils/hooks/useParamsValue.ts index 8a506ce7..9eb83370 100644 --- a/ui/src/lib/utils/hooks/useParamsValue.ts +++ b/ui/src/lib/utils/hooks/useParamsValue.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useRef } from "react"; +import { useCallback, useEffect } from "react"; import { useSearchParams } from "react-router-dom"; interface Params { @@ -6,13 +6,10 @@ interface Params { } const useParamsValue = (initialParams: Params) => { - const count = useRef(0); - const [searchParams, setSearchParams] = useSearchParams(initialParams); const updateParamsValue = useCallback( (key: string, value: string) => { - console.log(key, value); setSearchParams( (prev) => { prev.set(key, value); @@ -25,16 +22,14 @@ const useParamsValue = (initialParams: Params) => { ); useEffect(() => { - if (count.current === 0) { - for (const key in initialParams) { - if (initialParams[key]) { - const element = initialParams[key]; - updateParamsValue(key, element); - } + for (const key in initialParams) { + if (initialParams[key]) { + const element = initialParams[key]; + updateParamsValue(key, element); } - count.current = 1; } - }, [updateParamsValue, initialParams]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); return { searchParams, setSearchParams, updateParamsValue }; };