Skip to content

Commit

Permalink
feat: useHttpRequest에 isFetch옵션 추가(#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
eun-seong committed Mar 2, 2023
1 parent bd94d4e commit 7f7cd36
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useHttpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type IHttpRequestReturn<T, H = void> = [
boolean,
boolean,
boolean,
boolean,
number,
]
type CallbackFunctions<T> = {
Expand All @@ -19,6 +20,7 @@ export default function useHttpRequest<T, H = void>(
dataFetchCallback: (payload: H) => Promise<T>,
initialValue?: T,
): IHttpRequestReturn<T, H> {
const [isFetch, setIsFetch] = useState(false)
const [loading, setLoading] = useState(false)
const [isError, setError] = useState(false)
const [isSuccess, setSuccess] = useState(false)
Expand All @@ -34,6 +36,7 @@ export default function useHttpRequest<T, H = void>(
setSuccess(true)
setError(false)
callbacks?.onSuccess?.(data)
setIsFetch(true)
return data
})
.catch((e) => {
Expand All @@ -49,5 +52,5 @@ export default function useHttpRequest<T, H = void>(
})
}

return [data, fetch, loading, isSuccess, isError, fetchCount]
}
return [data, fetch, loading, isSuccess, isFetch, isError, fetchCount]
}

0 comments on commit 7f7cd36

Please sign in to comment.