Skip to content

Instantly share code, notes, and snippets.

@nabanita-sarkar
Last active February 2, 2022 16:52
Show Gist options
  • Save nabanita-sarkar/0acf0e042bf3e696a3f0e9b7629b4b92 to your computer and use it in GitHub Desktop.
Save nabanita-sarkar/0acf0e042bf3e696a3f0e9b7629b4b92 to your computer and use it in GitHub Desktop.
// 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`)
})
// 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