Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .changeset/rotten-grapes-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"react-router": minor
---

Stabilize `fetcher.reset()`

- ⚠️ This is a breaking change if you have begun using `fetcher.unstable_reset()`
Original file line number Diff line number Diff line change
Expand Up @@ -5498,9 +5498,7 @@ function testDomRouter(
<>
<p id="output">{`${fetcher.state}-${fetcher.data}`}</p>
<button onClick={() => fetcher.load("/")}>load</button>
<button onClick={() => fetcher.unstable_reset()}>
reset
</button>
<button onClick={() => fetcher.reset()}>reset</button>
</>
);
},
Expand Down
15 changes: 8 additions & 7 deletions packages/react-router/lib/dom/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
* @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.
Expand Down Expand Up @@ -2813,7 +2813,7 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
* })
*
* // reset fetcher
* fetcher.unstable_reset()
* fetcher.reset()
* }
*
* @public
Expand Down Expand Up @@ -2895,9 +2895,10 @@ export function useFetcher<T = any>({
[fetcherKey, submitImpl],
);

let unstable_reset = React.useCallback<
FetcherWithComponents<T>["unstable_reset"]
>((opts) => router.resetFetcher(fetcherKey, opts), [router, fetcherKey]);
let reset = React.useCallback<FetcherWithComponents<T>["reset"]>(
(opts) => router.resetFetcher(fetcherKey, opts),
[router, fetcherKey],
);

let FetcherForm = React.useMemo(() => {
let FetcherForm = React.forwardRef<HTMLFormElement, FetcherFormProps>(
Expand All @@ -2919,11 +2920,11 @@ export function useFetcher<T = any>({
Form: FetcherForm,
submit,
load,
unstable_reset,
reset,
...fetcher,
data,
}),
[FetcherForm, submit, load, unstable_reset, fetcher, data],
[FetcherForm, submit, load, reset, fetcher, data],
);

return fetcherWithComponents;
Expand Down