Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-react",
"version": "3.6.6",
"version": "3.6.7",
"description": "React hooks for data fetching",
"main": "dist/index.js",
"scripts": {
Expand Down
76 changes: 52 additions & 24 deletions src/hooks/use-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,14 +1333,22 @@ export function useFetch<FetchDataType = any, BodyType = any>(
}

useIsomorphicLayoutEffect(() => {
if (url !== '') {
if (!jsonCompare(previousProps.get(resolvedKey), optionsConfig)) {
abortControllers.get(resolvedKey)?.abort()
if (inDeps('data')) {
queue(initializeRevalidation)
const fn = () => {
if (url !== '') {
if (!jsonCompare(previousProps.get(resolvedKey), optionsConfig)) {
abortControllers.get(resolvedKey)?.abort()
if (inDeps('data')) {
queue(initializeRevalidation)
}
}
}
}
if (debounce) {
const tm = setTimeout(fn, debounce)
return () => clearTimeout(tm)
}
fn()
return () => {}
}, [serialize(optionsConfig), thisDeps, fetchState])

if (suspense) {
Expand All @@ -1365,26 +1373,36 @@ export function useFetch<FetchDataType = any, BodyType = any>(
}

useIsomorphicLayoutEffect(() => {
if (!runningRequests.get(resolvedKey) && isExpired) {
if (windowExists) {
if (canRevalidate && url !== '') {
if (
!jsonCompare(
JSON.parse(previousConfig.get(resolvedKey) || '{}'),
optionsConfig
)
) {
if (!isPending(resolvedKey)) {
if (inDeps('data')) {
initializeRevalidation()
const fn = () => {
if (!runningRequests.get(resolvedKey) && canRevalidate) {
if (windowExists) {
if (canRevalidate && url !== '') {
if (
!jsonCompare(
JSON.parse(previousConfig.get(resolvedKey) || '{}'),
optionsConfig
)
) {
if (!isPending(resolvedKey)) {
if (inDeps('data')) {
initializeRevalidation()
}
} else {
setLoading(true)
}
} else {
setLoading(true)
}
}
}
}
}

if (debounce) {
const tm = setTimeout(fn, debounce)
return () => clearTimeout(tm)
}
fn()

return () => {}
}, [resolvedKey, serialize(optionsConfig), canRevalidate, thisDeps])

useIsomorphicLayoutEffect(() => {
Expand All @@ -1403,16 +1421,26 @@ export function useFetch<FetchDataType = any, BodyType = any>(
}
}

if (revalidateAfterUnmount) {
if (suspense) {
if (suspenseInitialized.get(resolvedKey)) {
const fn = () => {
if (revalidateAfterUnmount) {
if (suspense) {
if (suspenseInitialized.get(resolvedKey)) {
revalidate()
}
} else {
revalidate()
}
} else {
revalidate()
}
}

if (debounce) {
const tm = setTimeout(fn, debounce)
return () => clearTimeout(tm)
}
fn()

return () => {}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [serialize(optionsConfig), thisDeps])

Expand Down
1 change: 0 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ export type FetchConfigType<FetchDataType = any, BodyType = any> = Omit<
formatBody?: boolean | ((b: BodyType) => any)
/**
* The time to wait before revalidation after props change
* @deprecated Use the `useDebounceFetch` hook instead
*/
debounce?: TimeSpan
/**
Expand Down