Skip to content

Commit

Permalink
Add reset to useMutation
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl committed Oct 1, 2024
1 parent a0308d2 commit 2eb779a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/react/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Mutation<Data, Variables> = readonly [
config?: MutationExtraConfig,
) => Future<Result<Data, ClientError>>,
AsyncData<Result<Data, ClientError>>,
{ reset: () => void },
];

export type MutationConfig<Data, Variables> = {
Expand Down Expand Up @@ -48,5 +49,9 @@ export const useMutation = <Data, Variables>(
[client, stableMutation],
);

return [commitMutation, data];
const reset = useCallback(() => {
setData(AsyncData.NotAsked());
}, []);

return [commitMutation, data, { reset }];
};

0 comments on commit 2eb779a

Please sign in to comment.