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

feat(react-router): add useSubmit/useFetcher to createMemoryRouter #10390

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
16 changes: 11 additions & 5 deletions packages/react-router-dom/__tests__/exports-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import * as ReactRouterDOM from "react-router-dom";

let nonReExportedKeys = new Set(["UNSAFE_mapRouteProperties"]);

let exportedButDifferent = new Set(["useFetcher", "useFetchers", "useSubmit"]);

describe("react-router-dom", () => {
for (let key in ReactRouter) {
if (!nonReExportedKeys.has(key)) {
it(`re-exports ${key} from react-router`, () => {
expect(ReactRouterDOM[key]).toBe(ReactRouter[key]);
});
} else {
if (nonReExportedKeys.has(key)) {
it(`does not re-export ${key} from react-router`, () => {
expect(ReactRouterDOM[key]).toBe(undefined);
});
} else if (exportedButDifferent.has(key)) {
it(`exports ${key} but not from react-router`, () => {
expect(ReactRouterDOM[key]).not.toBe(ReactRouter[key]);
});
} else {
it(`re-exports ${key} from react-router`, () => {
expect(ReactRouterDOM[key]).toBe(ReactRouter[key]);
});
}
}
});
7 changes: 4 additions & 3 deletions packages/react-router-dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ export interface SubmitOptions {
method?: HTMLFormMethod;

/**
* The action URL path used to submit the form. Overrides `<form action>`.
* Defaults to the path of the current route.
* The action URL path used to submit the form (or a direct action to be
* executed). Overrides `<form action>`. Defaults to the path of the current
* route.
*/
action?: string | ActionFunction;

/**
* The action URL used to submit the form. Overrides `<form encType>`.
* The encType to be used to encode the submission. Overrides `<form encType>`.
* Defaults to "application/x-www-form-urlencoded". Specifying `null` will
* opt-out of serialization and will submit the data directly to your action
* in the `payload` parameter.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ function useSubmitImpl(
let path =
typeof options.action === "function" ? null : options.action || action;
let routerAction =
typeof options.action === "function" ? options.action : null;
typeof options.action === "function" ? options.action : undefined;

// Base options shared between fetch() and navigate()
let opts = {
Expand Down
10 changes: 5 additions & 5 deletions packages/react-router-native/__tests__/exports-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ let nonReExportedKeys = new Set(["UNSAFE_mapRouteProperties"]);

describe("react-router-native", () => {
for (let key in ReactRouter) {
if (!nonReExportedKeys.has(key)) {
it(`re-exports ${key} from react-router`, () => {
expect(ReactRouterNative[key]).toBe(ReactRouter[key]);
});
} else {
if (nonReExportedKeys.has(key)) {
it(`does not re-export ${key} from react-router`, () => {
expect(ReactRouterNative[key]).toBe(undefined);
});
} else {
it(`re-exports ${key} from react-router`, () => {
expect(ReactRouterNative[key]).toBe(ReactRouter[key]);
});
}
}
});
6 changes: 6 additions & 0 deletions packages/react-router-native/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type {
unstable_BlockerFunction,
DataRouteMatch,
DataRouteObject,
FetcherWithMethods,
Fetcher,
Hash,
IndexRouteObject,
Expand Down Expand Up @@ -62,6 +63,8 @@ export type {
RoutesProps,
Search,
ShouldRevalidateFunction,
SubmitFunction,
SubmitOptions,
To,
} from "react-router";
export {
Expand Down Expand Up @@ -92,6 +95,8 @@ export {
useActionData,
useAsyncError,
useAsyncValue,
useFetcher,
useFetchers,
unstable_useBlocker,
useHref,
useInRouterContext,
Expand All @@ -110,6 +115,7 @@ export {
useRouteError,
useRouteLoaderData,
useRoutes,
useSubmit,
} from "react-router";

///////////////////////////////////////////////////////////////////////////////
Expand Down
Loading