Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 332x 332x | import * as React from "react";
import type { NavigateOptions } from "@tanstack/router-core";
import { doNothing } from "remeda";
import type {
OutputRouteSearchParams,
PathParams,
RouteId,
RouteTo,
SearchParamStateByRoute,
} from "~app/utils/navigation";
import type { TreeRouter } from "~web/entry/router";
export type NavigationContextType = {
useNavigate: () => <K extends RouteTo>(
options: Omit<NavigateOptions<TreeRouter, "/", K>, "from" | "href">,
) => void;
useParams: <K extends RouteId>(routeKey: K) => PathParams<K>;
usePush: () => (url: string) => void;
useBack: () => () => void;
usePathname: () => string;
useSearchParams: <K extends RouteId>(key: K) => OutputRouteSearchParams<K>;
useUpdateSearchParam: <K extends RouteId>(
key: K,
) => <P extends keyof OutputRouteSearchParams<K>>(
param: P,
) => SearchParamStateByRoute<K, P>[1];
};
const noop = doNothing();
export const NavigationContext = React.createContext<NavigationContextType>({
useNavigate: () => noop,
useParams: () => ({}),
usePush: () => noop,
useBack: () => noop,
usePathname: () => "unknown",
useSearchParams: () => ({}),
useUpdateSearchParam: () => () => noop,
});
|