Skip to content

Commit 87a455f

Browse files
authored
Stabilize fetcher.reset() (#14545)
1 parent 2e8639d commit 87a455f

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.changeset/rotten-grapes-cough.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"react-router": minor
3+
---
4+
5+
Stabilize `fetcher.reset()`
6+
7+
- ⚠️ This is a breaking change if you have begun using `fetcher.unstable_reset()`

packages/react-router/__tests__/dom/data-browser-router-test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5567,9 +5567,7 @@ function testDomRouter(
55675567
<>
55685568
<p id="output">{`${fetcher.state}-${fetcher.data}`}</p>
55695569
<button onClick={() => fetcher.load("/")}>load</button>
5570-
<button onClick={() => fetcher.unstable_reset()}>
5571-
reset
5572-
</button>
5570+
<button onClick={() => fetcher.reset()}>reset</button>
55735571
</>
55745572
);
55755573
},

packages/react-router/lib/dom/lib.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,7 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
28202820
* @param reason Optional `reason` to provide to [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)
28212821
* @returns void
28222822
*/
2823-
unstable_reset: (opts?: { reason?: unknown }) => void;
2823+
reset: (opts?: { reason?: unknown }) => void;
28242824

28252825
/**
28262826
* Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
@@ -2911,7 +2911,7 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
29112911
* })
29122912
*
29132913
* // reset fetcher
2914-
* fetcher.unstable_reset()
2914+
* fetcher.reset()
29152915
* }
29162916
*
29172917
* @public
@@ -2995,9 +2995,10 @@ export function useFetcher<T = any>({
29952995
[fetcherKey, submitImpl],
29962996
);
29972997

2998-
let unstable_reset = React.useCallback<
2999-
FetcherWithComponents<T>["unstable_reset"]
3000-
>((opts) => resetFetcher(fetcherKey, opts), [resetFetcher, fetcherKey]);
2998+
let reset = React.useCallback<FetcherWithComponents<T>["reset"]>(
2999+
(opts) => resetFetcher(fetcherKey, opts),
3000+
[resetFetcher, fetcherKey],
3001+
);
30013002

30023003
let FetcherForm = React.useMemo(() => {
30033004
let FetcherForm = React.forwardRef<HTMLFormElement, FetcherFormProps>(
@@ -3019,11 +3020,11 @@ export function useFetcher<T = any>({
30193020
Form: FetcherForm,
30203021
submit,
30213022
load,
3022-
unstable_reset,
3023+
reset,
30233024
...fetcher,
30243025
data,
30253026
}),
3026-
[FetcherForm, submit, load, unstable_reset, fetcher, data],
3027+
[FetcherForm, submit, load, reset, fetcher, data],
30273028
);
30283029

30293030
return fetcherWithComponents;

0 commit comments

Comments
 (0)