Implementation of fetching, adding and updating todos to db

This commit is contained in:
Dejan
2024-10-13 13:34:31 +02:00
parent f4be82587c
commit 515b5738bb
8 changed files with 205 additions and 120 deletions

View File

@ -0,0 +1,24 @@
import { useMutation, useQueryClient } from "react-query";
import firestore from "@react-native-firebase/firestore";
import { IToDo } from "@/hooks/firebase/types/todoData";
export const useUpdateTodo = () => {
const queryClients = useQueryClient()
return useMutation({
mutationKey: ["updateTodo"],
mutationFn: async (todoData: Partial<IToDo>) => {
try {
await firestore()
.collection("Todos")
.doc(todoData.id)
.update(todoData);
} catch (e) {
console.error(e)
}
},
onSuccess: () => {
queryClients.invalidateQueries("todos")
}
})
}