T
TanStack4y ago
like-gold

useMutation and FormData

Any idea why my formData is not being picked up by useMutation? The network request is successful but the formData is not being sent. The data is being sent with empty strings. .
const useUpdateUser = (type, legalName, idFrontImage, idBackImage) => {

console.log(legalName, personalNumber); // visible

let formData = new FormData();
formData.append("type", type);
formData.append("legal_name", legalName);
formData.append("id_front", idFrontImage);
formData.append("id_back", idBackImage);

console.log(formData); // not visible in formData object

return useMutation(
async (formData) =>
await axios({
url: useUpdateUserUrl,
headers: {
"Content-Type": "multipart/form-data",
...getHeaders(reduxState)
},
method: "put",
data: formData,
responseType: "json"
})
);
}
const useUpdateUser = (type, legalName, idFrontImage, idBackImage) => {

console.log(legalName, personalNumber); // visible

let formData = new FormData();
formData.append("type", type);
formData.append("legal_name", legalName);
formData.append("id_front", idFrontImage);
formData.append("id_back", idBackImage);

console.log(formData); // not visible in formData object

return useMutation(
async (formData) =>
await axios({
url: useUpdateUserUrl,
headers: {
"Content-Type": "multipart/form-data",
...getHeaders(reduxState)
},
method: "put",
data: formData,
responseType: "json"
})
);
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?