Even more code styling things

This commit is contained in:
2023-07-31 12:41:19 +03:00
parent 9eb30d2066
commit 9b35a54ae9
51 changed files with 127 additions and 113 deletions

View File

@ -15,7 +15,7 @@ type UseFetchSucced<T> = {
type UseFetchErrored = {
error: string,
data: undefined
data: undefined,
} & UseFetchShared
type UseFetchReturn<T> = UseFetchSucced<T> | UseFetchErrored
@ -35,7 +35,7 @@ function useFetch<R, T extends NonNullable<unknown>>(
guardResponse: (data: unknown) => data is R,
processResponse: (data: R) => T,
initialData?: T,
params?: Omit<RequestInit, 'method'>
params?: Omit<RequestInit, 'method'>,
): UseFetchReturn<T> {
const [data, setData] = useState(initialData)
@ -46,7 +46,7 @@ function useFetch<R, T extends NonNullable<unknown>>(
guardResponse,
processResponse,
true,
params
params,
)
function refetch() {
@ -62,11 +62,11 @@ function useFetch<R, T extends NonNullable<unknown>>(
return {
...(
error === null ? ({
data: data!, error: null
data: data!, error: null,
}) : ({ data: undefined, error })
),
loading,
refetch
refetch,
}
}