diff --git a/.changeset/rotten-grapes-cough.md b/.changeset/rotten-grapes-cough.md new file mode 100644 index 0000000000..9b5da8b557 --- /dev/null +++ b/.changeset/rotten-grapes-cough.md @@ -0,0 +1,7 @@ +--- +"react-router": minor +--- + +Stabilize `fetcher.reset()` + +- ⚠️ This is a breaking change if you have begun using `fetcher.unstable_reset()` diff --git a/packages/react-router/__tests__/dom/data-browser-router-test.tsx b/packages/react-router/__tests__/dom/data-browser-router-test.tsx index 6d05d6e883..eda3599f2e 100644 --- a/packages/react-router/__tests__/dom/data-browser-router-test.tsx +++ b/packages/react-router/__tests__/dom/data-browser-router-test.tsx @@ -5498,9 +5498,7 @@ function testDomRouter( <>

{`${fetcher.state}-${fetcher.data}`}

- + ); }, diff --git a/packages/react-router/lib/dom/lib.tsx b/packages/react-router/lib/dom/lib.tsx index cff63d829d..d8c07a0748 100644 --- a/packages/react-router/lib/dom/lib.tsx +++ b/packages/react-router/lib/dom/lib.tsx @@ -2722,7 +2722,7 @@ export type FetcherWithComponents = Fetcher & { * @param reason Optional `reason` to provide to [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) * @returns void */ - unstable_reset: (opts?: { reason?: unknown }) => void; + reset: (opts?: { reason?: unknown }) => void; /** * Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called. @@ -2813,7 +2813,7 @@ export type FetcherWithComponents = Fetcher & { * }) * * // reset fetcher - * fetcher.unstable_reset() + * fetcher.reset() * } * * @public @@ -2895,9 +2895,10 @@ export function useFetcher({ [fetcherKey, submitImpl], ); - let unstable_reset = React.useCallback< - FetcherWithComponents["unstable_reset"] - >((opts) => router.resetFetcher(fetcherKey, opts), [router, fetcherKey]); + let reset = React.useCallback["reset"]>( + (opts) => router.resetFetcher(fetcherKey, opts), + [router, fetcherKey], + ); let FetcherForm = React.useMemo(() => { let FetcherForm = React.forwardRef( @@ -2919,11 +2920,11 @@ export function useFetcher({ Form: FetcherForm, submit, load, - unstable_reset, + reset, ...fetcher, data, }), - [FetcherForm, submit, load, unstable_reset, fetcher, data], + [FetcherForm, submit, load, reset, fetcher, data], ); return fetcherWithComponents;