-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added dynamic typing for
usePathname
and useSearchParams
fr…
…om 'next/navigation'
- Loading branch information
Showing
10 changed files
with
127 additions
and
27 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,22 @@ | ||
declare module 'next/navigation' { | ||
/** | ||
* Get a read-only URLSearchParams object. For example searchParams.get('foo') would return 'bar' when ?foo=bar | ||
* Learn more about URLSearchParams here: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams | ||
* | ||
* If used from `pages/`, the hook may return `null` when the router is not | ||
* ready. | ||
*/ | ||
export function useSearchParams(): ReadonlyURLSearchParams | null | ||
|
||
/** | ||
* Get the current pathname. For example, if the URL is | ||
* https://example.com/foo?bar=baz, the pathname would be /foo. | ||
* | ||
* If the hook is accessed from `pages/`, the pathname may be `null` when the | ||
* router is not ready. | ||
*/ | ||
export function usePathname(): string | null | ||
|
||
// Re-export the types for next/navigation. | ||
export * from 'next/dist/client/components/navigation' | ||
} |
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 @@ | ||
declare module 'next/navigation' { | ||
/** | ||
* Get a read-only URLSearchParams object. For example searchParams.get('foo') would return 'bar' when ?foo=bar | ||
* Learn more about URLSearchParams here: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams | ||
*/ | ||
export function useSearchParams(): ReadonlyURLSearchParams | ||
|
||
/** | ||
* Get the current pathname. For example, if the URL is | ||
* https://example.com/foo?bar=baz, the pathname would be /foo. | ||
*/ | ||
export function usePathname(): string | ||
|
||
// Re-export the types for next/navigation. | ||
export * from 'next/dist/client/components/navigation' | ||
} |
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
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