rsnext/packages/next/client/components/hooks-client.ts
Tim Neutkens 81b554f3c1
Rename todos (#38560)
Renames todos to split them / make it easier to find what has to be done for the new router.


## 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)
2022-07-12 16:32:27 +00:00

49 lines
1.4 KiB
TypeScript

// useLayoutSegments() // Only the segments for the current place. ['children', 'dashboard', 'children', 'integrations'] -> /dashboard/integrations (/dashboard/layout.js would get ['children', 'dashboard', 'children', 'integrations'])
import { useContext } from 'react'
import {
QueryContext,
// ParamsContext,
PathnameContext,
// LayoutSegmentsContext,
} from './hooks-client-context'
import {
AppRouterContext,
AppTreeContext,
} from '../../shared/lib/app-router-context'
export function useSearchParams() {
return useContext(QueryContext)
}
export function useSearchParam(key: string) {
const params = useContext(QueryContext)
return params[key]
}
// TODO-APP: Move the other router context over to this one
export function useRouter() {
return useContext(AppRouterContext)
}
// TODO-APP: getting all params when client-side navigating is non-trivial as it does not have route matchers so this might have to be a server context instead.
// export function useParams() {
// return useContext(ParamsContext)
// }
export function usePathname() {
return useContext(PathnameContext)
}
// TODO-APP: define what should be provided through context.
// export function useLayoutSegments() {
// return useContext(LayoutSegmentsContext)
// }
export function useSelectedLayoutSegment(
parallelRouteKey: string = 'children'
) {
const { tree } = useContext(AppTreeContext)
return tree[1][parallelRouteKey][0]
}