Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified edit-person script to accept WCA ID via query param and sear…
…ch option in country picker (#8975) * Modified edit-person script to accept WCA ID via query param * Review changes * Search in country picker * Review changes * Review change
- Loading branch information
1 parent
ff8b065
commit b0a7c5c
Showing
5 changed files
with
144 additions
and
58 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
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,28 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
function getQueryParamsFromBrowserUrl() { | ||
return Object.fromEntries(new URLSearchParams(window.location.search)); | ||
} | ||
|
||
export default function useQueryParams() { | ||
const [queryParams, setQueryParams] = useState(getQueryParamsFromBrowserUrl()); | ||
|
||
useEffect(() => { | ||
const searchParams = new URLSearchParams(queryParams).toString(); | ||
const currentSearchParams = window.location.search.startsWith('?') | ||
? window.location.search.split('?')[1] | ||
: window.location.search; | ||
if (currentSearchParams !== searchParams) { | ||
window.location.search = searchParams; | ||
} | ||
}, [queryParams]); | ||
|
||
const updateQueryParam = useCallback((key, value) => { | ||
setQueryParams({ | ||
...queryParams, | ||
[key]: value, | ||
}); | ||
}, [queryParams]); | ||
|
||
return [queryParams, updateQueryParam]; | ||
} |
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