@@ -2632,6 +2632,44 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
2632
2632
FetcherFormProps & React . RefAttributes < HTMLFormElement >
2633
2633
> ;
2634
2634
2635
+ /**
2636
+ * Loads data from a route. Useful for loading data imperatively inside user
2637
+ * events outside a normal button or form, like a combobox or search input.
2638
+ *
2639
+ * ```tsx
2640
+ * let fetcher = useFetcher()
2641
+ *
2642
+ * <input onChange={e => {
2643
+ * fetcher.load(`/search?q=${e.target.value}`)
2644
+ * }} />
2645
+ * ```
2646
+ */
2647
+ load : (
2648
+ href : string ,
2649
+ opts ?: {
2650
+ /**
2651
+ * Wraps the initial state update for this `fetcher.load` in a
2652
+ * [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
2653
+ * call instead of the default [`React.startTransition`](https://react.dev/reference/react/startTransition).
2654
+ * This allows you to perform synchronous DOM actions immediately after the
2655
+ * update is flushed to the DOM.
2656
+ */
2657
+ flushSync ?: boolean ;
2658
+ } ,
2659
+ ) => Promise < void > ;
2660
+
2661
+ /**
2662
+ * Reset a fetcher back to an empty/idle state.
2663
+ *
2664
+ * If the fetcher is currently in-flight, the
2665
+ * [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
2666
+ * will be aborted with the `reason`, if provided.
2667
+ *
2668
+ * @param reason Optional `reason` to provide to [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)
2669
+ * @returns void
2670
+ */
2671
+ unstable_reset : ( opts ?: { reason ?: unknown } ) => void ;
2672
+
2635
2673
/**
2636
2674
* Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
2637
2675
*
@@ -2685,32 +2723,6 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
2685
2723
* ```
2686
2724
*/
2687
2725
submit : FetcherSubmitFunction ;
2688
-
2689
- /**
2690
- * Loads data from a route. Useful for loading data imperatively inside user
2691
- * events outside a normal button or form, like a combobox or search input.
2692
- *
2693
- * ```tsx
2694
- * let fetcher = useFetcher()
2695
- *
2696
- * <input onChange={e => {
2697
- * fetcher.load(`/search?q=${e.target.value}`)
2698
- * }} />
2699
- * ```
2700
- */
2701
- load : (
2702
- href : string ,
2703
- opts ?: {
2704
- /**
2705
- * Wraps the initial state update for this `fetcher.load` in a
2706
- * [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
2707
- * call instead of the default [`React.startTransition`](https://react.dev/reference/react/startTransition).
2708
- * This allows you to perform synchronous DOM actions immediately after the
2709
- * update is flushed to the DOM.
2710
- */
2711
- flushSync ?: boolean ;
2712
- } ,
2713
- ) => Promise < void > ;
2714
2726
} ;
2715
2727
2716
2728
// TODO: (v7) Change the useFetcher generic default from `any` to `unknown`
@@ -2745,6 +2757,9 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
2745
2757
* method: "post",
2746
2758
* encType: "application/json"
2747
2759
* })
2760
+ *
2761
+ * // reset fetcher
2762
+ * fetcher.unstable_reset()
2748
2763
* }
2749
2764
*
2750
2765
* @public
@@ -2826,6 +2841,10 @@ export function useFetcher<T = any>({
2826
2841
[ fetcherKey , submitImpl ] ,
2827
2842
) ;
2828
2843
2844
+ let unstable_reset = React . useCallback <
2845
+ FetcherWithComponents < T > [ "unstable_reset" ]
2846
+ > ( ( opts ) => router . resetFetcher ( fetcherKey , opts ) , [ router , fetcherKey ] ) ;
2847
+
2829
2848
let FetcherForm = React . useMemo ( ( ) => {
2830
2849
let FetcherForm = React . forwardRef < HTMLFormElement , FetcherFormProps > (
2831
2850
( props , ref ) => {
@@ -2846,10 +2865,11 @@ export function useFetcher<T = any>({
2846
2865
Form : FetcherForm ,
2847
2866
submit,
2848
2867
load,
2868
+ unstable_reset,
2849
2869
...fetcher ,
2850
2870
data,
2851
2871
} ) ,
2852
- [ FetcherForm , submit , load , fetcher , data ] ,
2872
+ [ FetcherForm , submit , load , unstable_reset , fetcher , data ] ,
2853
2873
) ;
2854
2874
2855
2875
return fetcherWithComponents ;
0 commit comments