create product
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import * as api from "../service/ProductService";
|
||||
import type { CreateCategoryType } from "../types/Types";
|
||||
|
||||
@@ -35,3 +35,22 @@ export const useGetCategoryDetail = (id: string) => {
|
||||
enabled: !!id,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetProducts = () => {
|
||||
return useQuery({
|
||||
queryKey: ["products"],
|
||||
queryFn: api.getCategory,
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateProduct = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: api.createProduct,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["products"],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user