Last active
February 2, 2022 16:52
-
-
Save nabanita-sarkar/0acf0e042bf3e696a3f0e9b7629b4b92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in todo/all query we are fetching the list of all todos | |
const { isLoading, isError, data } = useQuery("todo/all", () => { | |
return axios.get(`http://localhost:4000/todo/all`) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// now when todo/create is successful we are invalidating todo/all | |
// So that todo list is being fetching in create new todo creation | |
const { isLoading, isError, mutateAsync } = useMutation( | |
"todo/create", | |
() => { | |
return axios.post("http://localhost:4000/todo/create", todo) | |
}, | |
{ | |
onSuccess: () => { | |
queryClient.invalidateQueries("todo/all") | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment