From 2eb779aae08bd66f32970b4b727241566cf37694 Mon Sep 17 00:00:00 2001 From: bloodyowl Date: Tue, 1 Oct 2024 16:41:56 +0200 Subject: [PATCH] Add reset to useMutation --- src/react/useMutation.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/react/useMutation.ts b/src/react/useMutation.ts index 1300e7e..e2ff316 100644 --- a/src/react/useMutation.ts +++ b/src/react/useMutation.ts @@ -13,6 +13,7 @@ export type Mutation = readonly [ config?: MutationExtraConfig, ) => Future>, AsyncData>, + { reset: () => void }, ]; export type MutationConfig = { @@ -48,5 +49,9 @@ export const useMutation = ( [client, stableMutation], ); - return [commitMutation, data]; + const reset = useCallback(() => { + setData(AsyncData.NotAsked()); + }, []); + + return [commitMutation, data, { reset }]; };