generated from UniversityOfHelsinkiCS/toskaboiler
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(summary-v2): Store summary opts in query string
- Loading branch information
1 parent
34ebb99
commit 55b3f2e
Showing
2 changed files
with
67 additions
and
11 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,16 @@ | ||
import React from 'react' | ||
import { useLocation } from 'react-router' | ||
|
||
const useURLSearchParams = () => { | ||
const location = useLocation() | ||
const params = React.useMemo(() => new URLSearchParams(location.search), [location.search]) | ||
return [ | ||
params, | ||
React.useCallback(nextParams => { | ||
const nextSearch = nextParams.toString() | ||
window.history.replaceState({}, '', `${location.pathname}?${nextSearch}`) | ||
}, []), | ||
] | ||
} | ||
|
||
export default useURLSearchParams |
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