mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-25 06:01:29 +10:00
26 lines
640 B
TypeScript
26 lines
640 B
TypeScript
import { useMutation } from "@tanstack/react-query";
|
|
import { AxiosResponse } from "axios";
|
|
|
|
import { axios } from "@/client/libs/axios";
|
|
|
|
export const uploadImage = (file: File) => {
|
|
const formData = new FormData();
|
|
formData.append("file", file);
|
|
|
|
return axios.put<string, AxiosResponse<string>, FormData>("/storage/image", formData, {
|
|
headers: { "Content-Type": "multipart/form-data" },
|
|
});
|
|
};
|
|
|
|
export const useUploadImage = () => {
|
|
const {
|
|
error,
|
|
isPending: loading,
|
|
mutateAsync: uploadImageFn,
|
|
} = useMutation({
|
|
mutationFn: uploadImage,
|
|
});
|
|
|
|
return { uploadImage: uploadImageFn, loading, error };
|
|
};
|