Skip to content

Commit f7cc214

Browse files
authored
Check for FormData before checking for object when preparing body (#249)
* Check for FormData before checking for object when preparing body * Add todo * Cleanup
1 parent 335f505 commit f7cc214

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,8 @@ Todos
10971097
10981098
- [ ] make code editor plugin/package/extension that adds GraphQL syntax highlighting for `useQuery` and `useMutation` 😊
10991099
1100+
- [ ] add React Native test suite
1101+
11001102
[1]: https://github.com/ava/use-http/issues/new?title=[Feature%20Request]%20YOUR_FEATURE_NAME
11011103
[2]: https://github.com/ava/use-http/issues/93#issuecomment-600896722
11021104
[3]: https://github.com/ava/use-http/raw/master/public/dog.png

src/doFetchArgs.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export default async function doFetchArgs<TData = any>(
3737
const url = `${initialURL}${path}${route}`
3838

3939
const body = ((): BodyInit | null => {
40-
if (isBodyObject(routeOrBody)) return JSON.stringify(routeOrBody)
40+
// FormData instanceof check should go first, because React Native's FormData implementation
41+
// is indistinguishable from plain object when using isBodyObject check
4142
if (routeOrBody instanceof FormData) return routeOrBody
43+
if (isBodyObject(routeOrBody)) return JSON.stringify(routeOrBody)
4244
if (
4345
!isServer &&
4446
((bodyAs2ndParam as any) instanceof FormData ||

0 commit comments

Comments
 (0)