Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-framework] add tsdoc comments for withRouter and useRouter functions #2784

Merged
merged 7 commits into from Oct 11, 2021
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
beerose marked this conversation as resolved.
Show resolved Hide resolved
* @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