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

Add additional comments to new router #38986

Merged
merged 18 commits into from Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 17 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
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