-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into work
- Loading branch information
Showing
5 changed files
with
69 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useCallback, useEffect } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
|
||
interface Params { | ||
[key: string]: string; | ||
} | ||
|
||
const useParamsValue = (initialParams: Params) => { | ||
const [searchParams, setSearchParams] = useSearchParams(initialParams); | ||
|
||
const updateParamsValue = useCallback( | ||
(key: string, value: string) => { | ||
setSearchParams( | ||
(prev) => { | ||
prev.set(key, value); | ||
return prev; | ||
}, | ||
{ replace: true } | ||
); | ||
}, | ||
[setSearchParams] | ||
); | ||
|
||
useEffect(() => { | ||
for (const key in initialParams) { | ||
if (initialParams[key]) { | ||
const element = initialParams[key]; | ||
updateParamsValue(key, element); | ||
} | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return { searchParams, setSearchParams, updateParamsValue }; | ||
}; | ||
|
||
export default useParamsValue; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters