-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sample): update samples to use custom-client with BodyType
- Loading branch information
Showing
5 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
samples/react-query/custom-client/src/api/mutator/custom-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const customClient = async <ResponseType>({ | ||
url, | ||
method, | ||
params, | ||
data, | ||
}: { | ||
url: string; | ||
method: 'get' | 'post' | 'put' | 'delete' | 'patch'; | ||
params?: URLSearchParams; | ||
data?: BodyType<any>; | ||
}) => { | ||
const { headers } = data; | ||
const response = await fetch(url + new URLSearchParams(params), { | ||
method, | ||
headers, | ||
...(data ? { body: JSON.stringify(data) } : {}), | ||
}); | ||
|
||
return (await response.json()) as ResponseType; | ||
}; | ||
|
||
export default customClient; | ||
|
||
export type ErrorType<ErrorData> = ErrorData; | ||
|
||
export type BodyType<BodyData> = BodyData & { headers?: any }; |
21 changes: 0 additions & 21 deletions
21
samples/react-query/custom-client/src/api/mutator/custom-instance.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters