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
Show file tree
Hide file tree
Changes from 3 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
22 changes: 22 additions & 0 deletions nextjs/packages/next/client/image.tsx
Expand Up @@ -282,6 +282,28 @@ function handleLoading(
}

export default Image
/**
beerose marked this conversation as resolved.
Show resolved Hide resolved
* To add an image to your application, import the Image component:
*
* It renders a `img` element.
*
* @example
* ```
* import { Image } from "blitz"
* import profilePic from "../public/me.png"
*
* function Home() {
* return (
* <>
* <h1>My Homepage</h1>
* <Image src={profilePic} alt="Picture of the author" />
* <p>Welcome to my homepage!</p>
* </>
* )
* }
*
* @see Docs https://blitzjs.com/docs/image-component
*/
export function Image({
src,
sizes,
Expand Down
23 changes: 23 additions & 0 deletions nextjs/packages/next/client/script.tsx
Expand Up @@ -126,6 +126,29 @@ export function initScriptLoader(scriptLoaderItems: ScriptProps[]) {
scriptLoaderItems.forEach(handleClientScriptLoad)
}

/**
maybebored marked this conversation as resolved.
Show resolved Hide resolved
* With `<Script>`, you can define the strategy property and
* Blitz.js will optimize loading for the script:
*
* With `<Script>`, you no longer need to wrap scripts in <Head>.
*
*
* @example
* ```
* import { Script } from "blitz"
*
* function Home() {
* return (
* <>
* <Script src="https://www.google-analytics.com/analytics.js" />
* </>
* )
* }
* ```
*
* @param props {@link ScriptProps}
* @see Docs {@link https://blitzjs.com/docs/script-component}
*/
export function Script(props: ScriptProps): JSX.Element | null {
const {
src = '',
Expand Down
26 changes: 26 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 wraps a React
* component `router` object as a prop.
maybebored marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* ```
* import {withRouter} from "blitz"
*
* function Page({router}) {
* return <p>{router.pathname}</p>
* }
*
* export default withRouter(Page)
* ```
*
* @param WrappedComponent - Component to that needs router in its props
maybebored marked this conversation as resolved.
Show resolved Hide resolved
* @returns A component that has `router` object as prop.
maybebored 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,13 @@ export const withRouter: typeof withNextRouter = (WrappedComponent) => {
return withNextRouter(Wrapper)
}

/**
* `useRouter` is a custom React hook used to expose
* the router object within components.
maybebored marked this conversation as resolved.
Show resolved Hide resolved
*
* @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