@@ -1333,14 +1333,22 @@ export function useFetch<FetchDataType = any, BodyType = any>(
1333
1333
}
1334
1334
1335
1335
useIsomorphicLayoutEffect ( ( ) => {
1336
- if ( url !== '' ) {
1337
- if ( ! jsonCompare ( previousProps . get ( resolvedKey ) , optionsConfig ) ) {
1338
- abortControllers . get ( resolvedKey ) ?. abort ( )
1339
- if ( inDeps ( 'data' ) ) {
1340
- queue ( initializeRevalidation )
1336
+ const fn = ( ) => {
1337
+ if ( url !== '' ) {
1338
+ if ( ! jsonCompare ( previousProps . get ( resolvedKey ) , optionsConfig ) ) {
1339
+ abortControllers . get ( resolvedKey ) ?. abort ( )
1340
+ if ( inDeps ( 'data' ) ) {
1341
+ queue ( initializeRevalidation )
1342
+ }
1341
1343
}
1342
1344
}
1343
1345
}
1346
+ if ( debounce ) {
1347
+ const tm = setTimeout ( fn , debounce )
1348
+ return ( ) => clearTimeout ( tm )
1349
+ }
1350
+ fn ( )
1351
+ return ( ) => { }
1344
1352
} , [ serialize ( optionsConfig ) , thisDeps , fetchState ] )
1345
1353
1346
1354
if ( suspense ) {
@@ -1365,26 +1373,36 @@ export function useFetch<FetchDataType = any, BodyType = any>(
1365
1373
}
1366
1374
1367
1375
useIsomorphicLayoutEffect ( ( ) => {
1368
- if ( ! runningRequests . get ( resolvedKey ) && isExpired ) {
1369
- if ( windowExists ) {
1370
- if ( canRevalidate && url !== '' ) {
1371
- if (
1372
- ! jsonCompare (
1373
- JSON . parse ( previousConfig . get ( resolvedKey ) || '{}' ) ,
1374
- optionsConfig
1375
- )
1376
- ) {
1377
- if ( ! isPending ( resolvedKey ) ) {
1378
- if ( inDeps ( 'data' ) ) {
1379
- initializeRevalidation ( )
1376
+ const fn = ( ) => {
1377
+ if ( ! runningRequests . get ( resolvedKey ) && canRevalidate ) {
1378
+ if ( windowExists ) {
1379
+ if ( canRevalidate && url !== '' ) {
1380
+ if (
1381
+ ! jsonCompare (
1382
+ JSON . parse ( previousConfig . get ( resolvedKey ) || '{}' ) ,
1383
+ optionsConfig
1384
+ )
1385
+ ) {
1386
+ if ( ! isPending ( resolvedKey ) ) {
1387
+ if ( inDeps ( 'data' ) ) {
1388
+ initializeRevalidation ( )
1389
+ }
1390
+ } else {
1391
+ setLoading ( true )
1380
1392
}
1381
- } else {
1382
- setLoading ( true )
1383
1393
}
1384
1394
}
1385
1395
}
1386
1396
}
1387
1397
}
1398
+
1399
+ if ( debounce ) {
1400
+ const tm = setTimeout ( fn , debounce )
1401
+ return ( ) => clearTimeout ( tm )
1402
+ }
1403
+ fn ( )
1404
+
1405
+ return ( ) => { }
1388
1406
} , [ resolvedKey , serialize ( optionsConfig ) , canRevalidate , thisDeps ] )
1389
1407
1390
1408
useIsomorphicLayoutEffect ( ( ) => {
@@ -1403,16 +1421,26 @@ export function useFetch<FetchDataType = any, BodyType = any>(
1403
1421
}
1404
1422
}
1405
1423
1406
- if ( revalidateAfterUnmount ) {
1407
- if ( suspense ) {
1408
- if ( suspenseInitialized . get ( resolvedKey ) ) {
1424
+ const fn = ( ) => {
1425
+ if ( revalidateAfterUnmount ) {
1426
+ if ( suspense ) {
1427
+ if ( suspenseInitialized . get ( resolvedKey ) ) {
1428
+ revalidate ( )
1429
+ }
1430
+ } else {
1409
1431
revalidate ( )
1410
1432
}
1411
- } else {
1412
- revalidate ( )
1413
1433
}
1414
1434
}
1415
1435
1436
+ if ( debounce ) {
1437
+ const tm = setTimeout ( fn , debounce )
1438
+ return ( ) => clearTimeout ( tm )
1439
+ }
1440
+ fn ( )
1441
+
1442
+ return ( ) => { }
1443
+
1416
1444
// eslint-disable-next-line react-hooks/exhaustive-deps
1417
1445
} , [ serialize ( optionsConfig ) , thisDeps ] )
1418
1446
0 commit comments