mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
fixes and bug features
This commit is contained in:
21
hooks/firebase/useDeleteGrocery.ts
Normal file
21
hooks/firebase/useDeleteGrocery.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
|
||||
export const useDeleteGrocery = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["deleteGrocery"],
|
||||
mutationFn: async (groceryId: string) => {
|
||||
try {
|
||||
await firestore().collection("Groceries").doc(groceryId).delete();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw new Error("Failed to delete the grocery item.");
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries("groceries");
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user