Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/react-router/__tests__/dom/trailing-slashes-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,9 @@ describe("trailing slashes", () => {

function SetSearchParams() {
let [, setSearchParams] = useSearchParams();
React.useEffect(
() => setSearchParams({ key: "value" }),
[setSearchParams],
);
React.useEffect(() => {
setSearchParams({ key: "value" });
}, [setSearchParams]);
return <h1>👋</h1>;
}

Expand All @@ -631,10 +630,9 @@ describe("trailing slashes", () => {

function SetSearchParams() {
let [, setSearchParams] = useSearchParams();
React.useEffect(
() => setSearchParams({ key: "value" }),
[setSearchParams],
);
React.useEffect(() => {
setSearchParams({ key: "value" });
}, [setSearchParams]);
return <h1>👋</h1>;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/lib/dom/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ export function useSearchParams(
: nextInit,
);
hasSetSearchParamsRef.current = true;
navigate("?" + newSearchParams, navigateOptions);
return navigate("?" + newSearchParams, navigateOptions);
},
[navigate, searchParams],
);
Expand Down Expand Up @@ -2354,7 +2354,7 @@ export type SetURLSearchParams = (
| URLSearchParamsInit
| ((prev: URLSearchParams) => URLSearchParamsInit),
navigateOpts?: NavigateOptions,
) => void;
) => Promise<void>;

/**
* Submits a HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
Expand Down
14 changes: 8 additions & 6 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export function useMatch<
* The interface for the `navigate` function returned from {@link useNavigate}.
*/
export interface NavigateFunction {
(to: To, options?: NavigateOptions): void | Promise<void>;
(delta: number): void | Promise<void>;
(to: To, options?: NavigateOptions): Promise<void>;
(delta: number): Promise<void>;
}

const navigateEffectWarning =
Expand Down Expand Up @@ -355,11 +355,11 @@ function useNavigateUnstable(): NavigateFunction {

// Short circuit here since if this happens on first render the navigate
// is useless because we haven't wired up our history listener yet
if (!activeRef.current) return;
if (!activeRef.current) return Promise.resolve();

if (typeof to === "number") {
navigator.go(to);
return;
return Promise.resolve();
}

let path = resolveTo(
Expand Down Expand Up @@ -387,6 +387,8 @@ function useNavigateUnstable(): NavigateFunction {
options.state,
options,
);

return Promise.resolve();
},
[
basename,
Expand Down Expand Up @@ -1757,9 +1759,9 @@ function useNavigateStable(): NavigateFunction {
if (!activeRef.current) return;

if (typeof to === "number") {
router.navigate(to);
return router.navigate(to);
} else {
await router.navigate(to, { fromRouteId: id, ...options });
return router.navigate(to, { fromRouteId: id, ...options });
}
},
[router, id],
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ export function createRouter(init: RouterInit): Router {
location: nextLocation,
});
// Send the same navigation through
navigate(to, opts);
return navigate(to, opts);
},
reset() {
let blockers = new Map(state.blockers);
Expand Down