diff --git a/package.json b/package.json index abae894..30f4e9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "http-react", - "version": "3.0.0", + "version": "3.0.1", "description": "React hooks for data fetching", "main": "dist/index.js", "scripts": { diff --git a/src/hooks/use-fetch.ts b/src/hooks/use-fetch.ts index 1096b30..19cbf62 100644 --- a/src/hooks/use-fetch.ts +++ b/src/hooks/use-fetch.ts @@ -829,6 +829,7 @@ export function useFetch( const n = { ...p, data: $$data ?? p.data, + online: p.online, loading: rpc?.loading ?? false, error: isDefined($$error) ? $$error : p.error, completedAttempts: $$completedAttempts ?? p.completedAttempts @@ -852,6 +853,7 @@ export function useFetch( queue(() => { canDebounce[resolvedKey] = true }, debounce) + return $$data } } } @@ -1172,23 +1174,29 @@ export function useFetch( const initializeRevalidation = React.useCallback( async function initializeRevalidation() { + let d = undefined if (canRevalidate) { if (url !== '') { - fetchData({ + d = await fetchData({ query: Object.keys(reqQuery) .map(q => [q, reqQuery[q]].join('=')) .join('&'), params: reqParams }) } else { + d = def // It means a url is not passed setFetchState(prev => ({ ...prev, loading: false, - error: hasErrors[resolvedDataKey] || hasErrors[resolvedKey] + error: hasErrors[resolvedDataKey] || hasErrors[resolvedKey], + completedAttempts: prev.completedAttempts })) } + } else { + d = def } + return d }, [serialize(serialize(optionsConfig)), fetchState] )