forked from polka_billy/porridger
Added initial loading setting
Enabled pushing to history on filter setting
This commit is contained in:
@ -19,16 +19,16 @@ type UseFetchErrored<T> = {
|
||||
data: undefined
|
||||
} & UseFetchShared<T>
|
||||
|
||||
const gotError = <T>(res: UseFetchErrored<T> | UseFetchSucced<T>): res is UseFetchErrored<T> => (
|
||||
type UseFetchReturn<T> = UseFetchSucced<T> | UseFetchErrored<T>
|
||||
|
||||
const gotError = <T>(res: UseFetchReturn<T>): res is UseFetchErrored<T> => (
|
||||
typeof res.error === 'string'
|
||||
)
|
||||
|
||||
const fallbackError = <T>(res: UseFetchSucced<T> | UseFetchErrored<T>) => (
|
||||
const fallbackError = <T>(res: UseFetchReturn<T>) => (
|
||||
gotError(res) ? res.error : res.data
|
||||
)
|
||||
|
||||
type UseFetchReturn<T> = UseFetchSucced<T> | UseFetchErrored<T>
|
||||
|
||||
function useFetch<R, T>(
|
||||
url: string,
|
||||
method: RequestInit['method'],
|
||||
@ -40,7 +40,7 @@ function useFetch<R, T>(
|
||||
): UseFetchReturn<T> {
|
||||
const [data, setData] = useState(initialData)
|
||||
|
||||
const { doSend, loading, error } = useSend(url, method, needAuth, guardResponse, processResponse, params)
|
||||
const { doSend, loading, error } = useSend(url, method, needAuth, guardResponse, processResponse, true, params)
|
||||
|
||||
useEffect(() => {
|
||||
doSend().then(
|
||||
|
Reference in New Issue
Block a user