From cfdfb69c4514225688d818e92aec66ec82f7f58b Mon Sep 17 00:00:00 2001 From: Mayuran Date: Mon, 11 Oct 2021 18:09:26 +0530 Subject: [PATCH] add tsdoc comments for `withRouter` and `useRouter` functions (#2784) (meta) --- packages/core/src/router/index.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/core/src/router/index.tsx b/packages/core/src/router/index.tsx index f83ab914bc..f54e2cc754 100644 --- a/packages/core/src/router/index.tsx +++ b/packages/core/src/router/index.tsx @@ -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

{router.pathname}

+ * } + * + * 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() @@ -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()