Skip to content

Commit

Permalink
refactor: update useRouter from next/router types
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Oct 28, 2022
1 parent 5d30eaf commit a84d916
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@
"no-obj-calls": "warn",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-redeclare": ["warn", { "builtinGlobals": false }],
"no-regex-spaces": "warn",
"no-restricted-syntax": [
"warn",
Expand Down Expand Up @@ -330,6 +329,10 @@
"react/style-prop-object": "warn",
"react-hooks/rules-of-hooks": "error",
// "@typescript-eslint/non-nullable-type-assertion-style": "warn",
"@typescript-eslint/prefer-as-const": "warn"
"@typescript-eslint/prefer-as-const": "warn",
"@typescript-eslint/no-redeclare": [
"warn",
{ "builtinGlobals": false, "ignoreDeclarationMerge": true }
]
}
}
6 changes: 4 additions & 2 deletions packages/next/client/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ export default singletonRouter as SingletonRouter
// Reexport the withRoute HOC
export { default as withRouter } from './with-router'

export function useRouter(): NextRouter {
export function useRouter(throwOnMissing: true): NextRouter
export function useRouter(): NextRouter | null
export function useRouter(throwOnMissing?: boolean) {
const router = React.useContext(RouterContext)
if (!router) {
if (!router && throwOnMissing) {
throw new Error('invariant expected pages router to be mounted')
}

Expand Down

0 comments on commit a84d916

Please sign in to comment.