Skip to content

Commit

Permalink
add tsdoc comments for withRouter and useRouter functions (#2784)
Browse files Browse the repository at this point in the history
(meta)
  • Loading branch information
maybebored committed Oct 11, 2021
1 parent 9e405aa commit cfdfb69
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/core/src/router/index.tsx
Expand Up @@ -22,6 +22,25 @@ export interface WithRouterProps {
router: BlitzRouter
}

/**
* `withRouter` is a higher-order component that takes a component and returns a new one
* with an additional `router` prop.
*
* @example
* ```
* import {withRouter} from "blitz"
*
* function Page({router}) {
* return <p>{router.pathname}</p>
* }
*
* export default withRouter(Page)
* ```
*
* @param WrappedComponent - a React component that needs `router` object in props
* @returns A component with a `router` object in props
* @see Docs {@link https://blitzjs.com/docs/router#router-object | router}
*/
export const withRouter: typeof withNextRouter = (WrappedComponent) => {
function Wrapper({router, ...props}: any) {
const query = useRouterQuery()
Expand All @@ -31,6 +50,12 @@ export const withRouter: typeof withNextRouter = (WrappedComponent) => {
return withNextRouter(Wrapper)
}

/**
* `useRouter` is a React hook used to access `router` object within components
*
* @returns `router` object
* @see Docs {@link https://blitzjs.com/docs/router#router-object | router}
*/
export function useRouter() {
const router = useNextRouter()
const query = useRouterQuery()
Expand Down

0 comments on commit cfdfb69

Please sign in to comment.