Skip to content

Commit

Permalink
Add additional comments to new router (#38986)
Browse files Browse the repository at this point in the history
Expanded app-render.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
  • Loading branch information
timneutkens committed Jul 26, 2022
1 parent 8c902b6 commit e2286ee
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 91 deletions.
1 change: 1 addition & 0 deletions packages/next/client/components/app-router.client.tsx
Expand Up @@ -41,6 +41,7 @@ function fetchFlight(
JSON.stringify(flightRouterState)
)

// TODO-APP: Verify that TransformStream is supported.
const { readable, writable } = new TransformStream()

fetch(flightUrl.toString()).then((res) => {
Expand Down
16 changes: 16 additions & 0 deletions packages/next/client/components/hooks-client.ts
Expand Up @@ -12,16 +12,25 @@ import {
AppTreeContext,
} from '../../shared/lib/app-router-context'

/**
* Get the current search params. For example useSearchParams() would return {"foo": "bar"} when ?foo=bar
*/
export function useSearchParams() {
return useContext(SearchParamsContext)
}

/**
* Get an individual search param. For example useSearchParam("foo") would return "bar" when ?foo=bar
*/
export function useSearchParam(key: string): string | string[] {
const params = useContext(SearchParamsContext)
return params[key]
}

// TODO-APP: Move the other router context over to this one
/**
* Get the router methods. For example router.push('/dashboard')
*/
export function useRouter(): import('../../shared/lib/app-router-context').AppRouterInstance {
return useContext(AppRouterContext)
}
Expand All @@ -31,6 +40,9 @@ export function useRouter(): import('../../shared/lib/app-router-context').AppRo
// return useContext(ParamsContext)
// }

/**
* Get the current pathname. For example usePathname() on /dashboard?foo=bar would return "/dashboard"
*/
export function usePathname(): string {
return useContext(PathnameContext)
}
Expand All @@ -40,6 +52,10 @@ export function usePathname(): string {
// return useContext(LayoutSegmentsContext)
// }

// TODO-APP: Expand description when the docs are written for it.
/**
* Get the current segment one level down from the layout.
*/
export function useSelectedLayoutSegment(
parallelRouteKey: string = 'children'
): string {
Expand Down

0 comments on commit e2286ee

Please sign in to comment.