This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Summary Closes #1750 **Proposal:** - Filtering `queryParams` when they are empty ## To test - Copy the link 'https://pr1881--gpswapui.review.gnosisdev.com/#/?referral=' - Empty URL queryParams will be removed.
- Loading branch information
1 parent
d8687e5
commit 443a98f
Showing
2 changed files
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect } from 'react' | ||
import { useHistory } from 'react-router-dom' | ||
import qs from 'qs' | ||
|
||
import useParsedQueryString from 'hooks/useParsedQueryString' | ||
|
||
/** | ||
* When query parameter is empty will be filtered | ||
* example: ?referral=¶mFullfilled=123 | ||
* result: {paramFullfilled: 123} | ||
* | ||
* @param queryParams The object to check | ||
*/ | ||
function filterEmptyQueryValues(queryParams: { [s: string]: unknown }) { | ||
return Object.fromEntries(Object.entries(queryParams).filter(([, v]) => v)) | ||
} | ||
|
||
export function useFilterEmptyQueryParams() { | ||
const queryParams = useParsedQueryString() | ||
const history = useHistory() | ||
|
||
useEffect(() => { | ||
history.replace({ | ||
search: qs.stringify(filterEmptyQueryValues(queryParams)), | ||
}) | ||
}, [history, queryParams]) | ||
} |
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