Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
support formdata
Browse files Browse the repository at this point in the history
  • Loading branch information
Atrox authored and fabien0102 committed Apr 12, 2020
1 parent 617a3e0 commit 23f6324
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/useMutate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ export function useMutate<

const options: RequestInit = {
method: verb,
headers: {
"content-type": typeof body === "object" ? "application/json" : "text/plain",
},
};

// don't set content-type when body is of type FormData
if (!(body instanceof FormData)) {
options.headers = { "content-type": typeof body === "object" ? "application/json" : "text/plain" };
}

if (!isDelete) {
options.body = typeof body === "object" ? JSON.stringify(body) : ((body as unknown) as string);
if (body instanceof FormData) {
options.body = body;
} else if (typeof body === "object") {
options.body = JSON.stringify(body);
} else {
options.body = (body as unknown) as string;
}
}

const signal = getAbortSignal();
Expand Down

0 comments on commit 23f6324

Please sign in to comment.