Skip to content

Commit f9279f7

Browse files
committed
chore: react router declaration merging
1 parent c985409 commit f9279f7

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/lib/router/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ export {
2525
export { useRouteError } from "./useRouteError";
2626
export { handleLazyImportError } from "./handleLazyImportError";
2727

28-
type StateCandidate = { from: string } | Record<string, unknown>;
29-
30-
export const useLocationState = () =>
31-
(useLocation().state as StateCandidate) ?? {};
28+
export const useLocationState = () => useLocation().state ?? {};
3229

3330
export const generatePath = (
3431
path: string,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// eslint-disable-next-line no-restricted-imports
2+
import type {
3+
NavigateOptions as RRNavigateOptions,
4+
Location as RRLocation,
5+
To,
6+
} from "react-router";
7+
8+
declare module "react-router" {
9+
interface NavigateState {
10+
from?: string;
11+
[key: string]: unknown;
12+
}
13+
14+
interface LocationWithState extends Omit<RRLocation, "state"> {
15+
state?: NavigateState;
16+
}
17+
18+
interface NavigateOptions extends Omit<RRNavigateOptions, "state"> {
19+
state?: NavigateState;
20+
}
21+
22+
interface NavigateFunction {
23+
(to: To, options?: NavigateOptions): void | Promise<void>;
24+
(delta: number): void | Promise<void>;
25+
}
26+
27+
function useLocation(): LocationWithState;
28+
function useNavigate(): NavigateFunction;
29+
}

0 commit comments

Comments
 (0)