-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): use routing for the AccountModal
- Loading branch information
1 parent
9256402
commit 02fc5e2
Showing
6 changed files
with
52 additions
and
26 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,17 @@ | ||
import { useLocation } from 'react-router'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
function useQueryParam(key: string): string | null { | ||
const [param, setParam] = useState<string | null>(null); | ||
const location = useLocation(); | ||
|
||
useEffect(() => { | ||
const urlSearchParams = new URLSearchParams(location.search); | ||
|
||
setParam(urlSearchParams.get(key)); | ||
}, [location]); | ||
|
||
return param; | ||
} | ||
|
||
export default useQueryParam; |
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,17 @@ | ||
import type { History } from 'history'; | ||
|
||
export function addQueryParam(history: History, key: string, value: string, method: 'replace' | 'push' = 'push') { | ||
const urlSearchParams = new URLSearchParams(history.location.search); | ||
|
||
urlSearchParams.set(key, value); | ||
|
||
history[method]({ pathname: history.location.pathname, search: urlSearchParams.toString() }); | ||
} | ||
|
||
export function removeQueryParam(history: History, key: string, method: 'replace' | 'push' = 'push') { | ||
const urlSearchParams = new URLSearchParams(history.location.search); | ||
|
||
urlSearchParams.delete(key); | ||
|
||
history[method]({ pathname: history.location.pathname, search: urlSearchParams.toString() }); | ||
} |