Skip to content

Commit

Permalink
fix: hook functions return headers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Feb 21, 2024
1 parent 1afac60 commit 72b7d26
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quick-dolls-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/react-core': minor
---

Hook request functions now return headers.
3 changes: 2 additions & 1 deletion libs/react-core/src/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosRequestConfig, AxiosResponse } from 'axios'
import { AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders } from 'axios'
import { MutatorCallback, MutatorOptions } from 'swr'
import { SWROptions } from './types'
import { AppSettings } from './useAppSettings'
Expand Down Expand Up @@ -190,6 +190,7 @@ export function mergeInternalCallbackArgs<
export type Response<T> = {
status: number
data?: T
headers?: AxiosResponseHeaders
error?: string
}

Expand Down
1 change: 1 addition & 0 deletions libs/react-core/src/useDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function useDeleteFunc<Params extends RequestParams, Result>(
return {
status: response.status,
data: response.data,
headers: response.headers,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Expand Down
1 change: 1 addition & 0 deletions libs/react-core/src/useGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function useGetFunc<Params extends RequestParams, Result>(
return {
status: response.status,
data: response.data,
headers: response.headers,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Expand Down
1 change: 1 addition & 0 deletions libs/react-core/src/usePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export function usePatchFunc<Params extends RequestParams, Payload, Result>(
return {
status: response.status,
data: response.data,
headers: response.headers,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Expand Down
1 change: 1 addition & 0 deletions libs/react-core/src/usePost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export function usePostFunc<Params extends RequestParams, Payload, Result>(
return {
status: response.status,
data: response.data,
headers: response.headers,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Expand Down
1 change: 1 addition & 0 deletions libs/react-core/src/usePut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export function usePutFunc<Params extends RequestParams, Payload, Result>(
return {
status: response.status,
data: response.data,
headers: response.headers,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Expand Down

0 comments on commit 72b7d26

Please sign in to comment.